本文整理汇总了TypeScript中@angular-devkit/schematics/testing.UnitTestTree.overwrite方法的典型用法代码示例。如果您正苦于以下问题:TypeScript UnitTestTree.overwrite方法的具体用法?TypeScript UnitTestTree.overwrite怎么用?TypeScript UnitTestTree.overwrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular-devkit/schematics/testing.UnitTestTree
的用法示例。
在下文中一共展示了UnitTestTree.overwrite方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should work as expected for a project with a root', async () => {
const originalContent = JSON.parse(tree.readContent('angular.json'));
originalContent.projects['migration-test'].root = 'src';
tree.overwrite('angular.json', JSON.stringify(originalContent));
const polyfillPath = '/src/polyfills.ts';
tree.overwrite(polyfillPath, oldPolyfills);
const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch())
.toPromise();
expect(tree2.readContent(polyfillPath)).not.toMatch(/import .*es7.*reflect.*;/);
});
示例2: it
it('should enable web-anmations and object.entries properly on projects with ng cli version >= 7.3', () => {
const polyfills = `
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run \`npm install --save classlist.js\`.
// import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
`;
const result = `
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run \`npm install --save classlist.js\`.
/** ES7 \`Object.entries\` needed for igxGrid to render in IE. */
import 'core-js/es7/object';
import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
`;
tree.create('src/polyfills.ts', polyfills);
const newJson: any = JSON.parse(tree.read('/angular.json').toString());
newJson.projects['testProj'].architect.build.options['es5BrowserSupport'] = false;
tree.overwrite('/angular.json', JSON.stringify(newJson));
runner.runSchematic('ng-add', { polyfills: true }, tree);
expect(tree.readContent('src/polyfills.ts').replace(/\r\n/g, '\n')).toEqual(result.replace(/\r\n/g, '\n'));
});
示例3: it
it('should wrap the bootstrap decleration in a DOMContentLoaded event handler', () => {
const filePath = '/projects/bar/src/main.ts';
appTree.overwrite(
filePath,
`
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { hmrBootstrap } from './hmr';
if (environment.production) {
enableProdMode();
}
const bootstrap = () => platformBrowserDynamic().bootstrapModule(AppModule);
if (!hmrBootstrap) {
bootstrap().catch(err => console.log(err));
}
`,
);
const tree = schematicRunner.runSchematic('universal', defaultOptions, appTree);
const contents = tree.readContent(filePath);
expect(contents).toMatch(
/document.addEventListener\('DOMContentLoaded', \(\) => {[\n\r\s]+bootstrap\(\)/,
);
});
示例4: it
it('should update theme import in sass files', done => {
const config = JSON.parse(JSON.stringify(configJson));
config.projects.testProj['schematics'] = {
'@schematics/angular:component': {
styleext: 'sass'
}
};
appTree.overwrite('/angular.json', JSON.stringify(config));
appTree.create(
'/testSrc/appPrefix/component/test.component.sass',
`@import "~igniteui-angular/core/styles/themes/index";`
);
appTree.create(
'/testSrc/testSrc/styles.sass',
`@import "~igniteui-angular/core/styles/themes/_index.scss";`
);
const tree = schematicRunner.runSchematic('migration-03', {}, appTree);
expect(tree.readContent('/testSrc/appPrefix/component/test.component.sass')).toEqual(
`@import "~igniteui-angular/lib/core/styles/themes/index";`
);
expect(tree.readContent('/testSrc/testSrc/styles.sass')).toEqual(
`@import "~igniteui-angular/lib/core/styles/themes/_index.scss";`
);
done();
});
示例5: it
it('should respect the sourceRoot value', () => {
const config = JSON.parse(appTree.readContent('/angular.json'));
config.projects.bar.sourceRoot = 'projects/bar/custom';
appTree.overwrite('/angular.json', JSON.stringify(config, null, 2));
appTree = schematicRunner.runSchematic('class', defaultOptions, appTree);
expect(appTree.files.indexOf('/projects/bar/custom/app/foo.ts')).toBeGreaterThanOrEqual(0);
});
示例6: it
it('should respect the sourceRoot value', () => {
const config = JSON.parse(appTree.readContent('/angular.json'));
config.projects.bar.sourceRoot = 'projects/bar/custom';
appTree.overwrite('/angular.json', JSON.stringify(config, null, 2));
appTree = schematicRunner.runSchematic('service', defaultOptions, appTree);
expect(appTree.files).toContain('/projects/bar/custom/app/foo/foo.service.ts');
});
示例7: makeInlineTemplate
function makeInlineTemplate(tree: UnitTestTree, template?: string): void {
template = template || `
<p>
App works!
</p>`;
const newText = `
import { Component, OnInit } from '@angular/core';
@Component({
selector: ''
template: \`
${template}
\`,
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
`;
tree.overwrite('/projects/bar/src/app/app.component.ts', newText);
tree.delete('/projects/bar/src/app/app.component.html');
}
示例8: it
it('should add a dev dependency to @angular-devkit/build-angular (no dev)', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree.overwrite('/package.json', JSON.stringify({}, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const content = tree.readContent('/package.json');
const pkg = JSON.parse(content);
expect(pkg.devDependencies['@angular-devkit/build-angular'])
.toBe(latestVersions.DevkitBuildAngular);
});