本文整理汇总了TypeScript中@angular-devkit/schematics/testing.UnitTestTree.readContent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript UnitTestTree.readContent方法的具体用法?TypeScript UnitTestTree.readContent怎么用?TypeScript UnitTestTree.readContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular-devkit/schematics/testing.UnitTestTree
的用法示例。
在下文中一共展示了UnitTestTree.readContent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should be a noop if key is not found', () => {
const content = JSON.stringify({foo: 'bar'});
tree.create('tmp', content);
const ast = parseJsonAst(content) as JsonAstObject;
let recorder = tree.beginUpdate('tmp');
expect(() => removeKeyValueInAstObject(recorder, content, ast, 'hello')).not.toThrow();
tree.commitUpdate(recorder);
const value = tree.readContent('tmp');
expect(JSON.parse(value)).toEqual({foo: 'bar'});
expect(value).toBe('{"foo":"bar"}');
});
示例2: it
it(`should not override existing users dependencies`, () => {
const oldPackageJson = workspaceTree.readContent('package.json');
workspaceTree.overwrite('package.json', oldPackageJson.replace(
`"typescript": "${latestVersions.TypeScript}"`,
`"typescript": "~2.5.2"`,
));
const tree = schematicRunner.runSchematic('library', defaultOptions, workspaceTree);
const packageJson = getJsonFileContent(tree, 'package.json');
expect(packageJson.devDependencies.typescript).toEqual('~2.5.2');
});
示例3: 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.*;/);
});
示例4: it
it('should add resourcesOutputPath to root assets when specified', async () => {
const config = JSON.parse(appTree.readContent('/angular.json'));
config.projects.bar.architect.build.configurations.production.resourcesOutputPath = 'outDir';
appTree.overwrite('/angular.json', JSON.stringify(config));
const tree = await schematicRunner.runSchematicAsync('service-worker', defaultOptions, appTree)
.toPromise();
const pkgText = tree.readContent('/projects/bar/ngsw-config.json');
const ngswConfig = JSON.parse(pkgText);
expect(ngswConfig.assetGroups[1].resources.files)
.toContain('/outDir/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)');
});
示例5: it
it('should handle a path in the name and module options', () => {
appTree = schematicRunner.runSchematic('module', { name: 'admin/module', project: 'bar' }, appTree);
const options = { ...defaultOptions, name: 'other/test-component', module: 'admin/module' };
appTree = schematicRunner.runSchematic('component', options, appTree);
const content = appTree.readContent('/projects/bar/src/app/admin/module/module.module.ts');
expect(content).toMatch(
// tslint:disable-next-line:max-line-length
/import { TestComponentComponent } from '..\/..\/other\/test-component\/test-component.component'/);
});
示例6: it
it('should not mark queries used in promises as static', async() => {
writeFile('/index.ts', `
import {Component, ${queryType}} from '@angular/core';
@Component({template: '<span #test></span>'})
export class MyComp {
private @${queryType}('test') query: any;
private @${queryType}('test') query2: any;
ngOnInit() {
const a = Promise.resolve();
Promise.resolve().then(() => {
this.query.doSomething();
});
Promise.reject().catch(() => {
this.query.doSomething();
});
a.then(() => {}).then(() => {
this.query.doSomething();
});
Promise.resolve().then(this.createPromiseCb());
}
createPromiseCb() {
this.query2.doSomething();
return () => { /* empty callback */}
}
}
`);
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`@${queryType}('test', { static: false }) query: any;`);
expect(tree.readContent('/index.ts'))
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
});
示例7: expect
.then(() => {
expect([...tree.files].sort()).toEqual([
'/a/b/file1',
'/a/b/file2',
'/a/b/file3',
'/a/b/file__norename__',
'/a/b/filefoo',
'/a/c/file4',
]);
expect(tree.readContent('/a/b/file3')).toBe('hello 1 world');
})
示例8: it
it('should remove Bazel-controlled options from tsconfig.json', () => {
host = schematicRunner.runSchematic('ng-add', defaultOptions, host);
expect(host.files).toContain('/tsconfig.json');
const content = host.readContent('/tsconfig.json');
expect(() => JSON.parse(content)).not.toThrow();
expect(JSON.parse(content)).toEqual({
compileOnSave: false,
compilerOptions: {
outDir: './dist/out-tsc',
}
});
});
示例9: it
it('should find existing Angular version', () => {
let host = new UnitTestTree(new HostTree);
host.create('/node_modules/@angular/core/package.json', JSON.stringify({
name: '@angular/core',
version: '6.6.6',
}));
const options = {...defaultOptions};
host = schematicRunner.runSchematic('bazel-workspace', options, host);
expect(host.files).toContain('/WORKSPACE');
const workspace = host.readContent('/WORKSPACE');
expect(workspace).toMatch('ANGULAR_VERSION = "6.6.6"');
});