本文整理汇总了TypeScript中@angular-devkit/schematics/testing.UnitTestTree类的典型用法代码示例。如果您正苦于以下问题:TypeScript UnitTestTree类的具体用法?TypeScript UnitTestTree怎么用?TypeScript UnitTestTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnitTestTree类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('Update 6.1.0', () => {
let appTree: UnitTestTree;
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
const configJson = {
defaultProject: 'testProj',
projects: {
testProj: {
sourceRoot: '/testSrc'
}
},
schematics: {
'@schematics/angular:component': {
prefix: 'appPrefix'
}
}
};
beforeEach(() => {
appTree = new UnitTestTree(new EmptyTree());
appTree.create('/angular.json', JSON.stringify(configJson));
});
it('should update igxToggle events and selectors', done => {
appTree.create(
'/testSrc/appPrefix/component/test.component.html',
`<igx-tab-bar attr igxForRemote="true"></igx-tab-bar>` +
`<elem igxToggle (onOpen)="handler" (onClose)="handler"></elem>`
);
const tree = schematicRunner.runSchematic('migration-04', {}, appTree);
expect(tree.readContent('/testSrc/appPrefix/component/test.component.html'))
.toEqual(
`<igx-bottom-nav attr></igx-bottom-nav>` +
`<elem igxToggle (onOpened)="handler" (onClosed)="handler"></elem>`);
done();
});
});
示例2: describe
describe('SASS', () => {
let host = new UnitTestTree(new HostTree);
beforeAll(() => {
host.create('/src/app/app.component.scss', '');
expect(host.files).toContain('/src/app/app.component.scss');
const options = {...defaultOptions};
host = schematicRunner.runSchematic('bazel-workspace', options, host);
expect(host.files).toContain('/WORKSPACE');
expect(host.files).toContain('/src/BUILD.bazel');
});
it('should download and load rules_sass in WORKSPACE', () => {
const content = host.readContent('/WORKSPACE');
expect(content).toContain('RULES_SASS_VERSION');
expect(content).toContain(
'load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")');
});
it('should add sass_binary rules in src/BUILD', () => {
const content = host.readContent('/src/BUILD.bazel');
expect(content).toContain('load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")');
expect(content).toContain('glob(["**/*.scss"])');
});
});
示例3: myProp
it('should detect static queries used through external getter access', () => {
writeFile('/index.ts', `
import {Component, ${queryType}} from '@angular/core';
import {External} from './external';
@Component({template: '<span #test></span>'})
export class MyComp {
@${queryType}('test') query: any;
private external = new External(this);
get myProp() {
return this.query.myValue;
}
ngOnInit() {
console.log(this.external.query);
}
}
`);
writeFile('/external.ts', `
import {MyComp} from './index';
export class External {
constructor(private comp: MyComp) {}
get query() { return this.comp.query; }
}
`);
runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`@${queryType}('test', { static: true }) query: any;`);
});
示例4: it
it('should update Sass files', done => {
appTree.create(
'/testSrc/appPrefix/style.scss',
`$dark-chip-theme: igx-chip-theme(
$roundness: 4px,
$chip-background: #180505,
$chip-hover-background: white,
$remove-icon-color: red,
$dir-icon-color: yellow,
$selected-chip-hover-background: gray
);`
);
const tree = schematicRunner.runSchematic('migration-06', {}, appTree);
expect(tree.readContent('/testSrc/appPrefix/style.scss'))
.toEqual(
`$dark-chip-theme: igx-chip-theme(
$roundness: 4px,
$background: #180505,
$hover-background: white,
$hover-selected-background: gray
);`
);
done();
});
示例5: runMigration
it('should detect inherited queries', async() => {
writeFile('/index.ts', `
import {Component, NgModule, ViewChild} from '@angular/core';
export class BaseClass {
@ViewChild('myRef') query: any;
}
@Component({templateUrl: 'my-tmpl.html'})
export class MyComp extends BaseClass {}
@NgModule({declarations: [MyComp]})
export class MyModule {}
`);
writeFile(`/my-tmpl.html`, `
<span #myRef>My Ref</span>
`);
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`@ViewChild('myRef', { static: true }) query: any;`);
});
示例6: myProperty
it('should detect input decorator on setter', async() => {
writeFile('/index.ts', `
import {Input, Component, ${queryType}} from '@angular/core';
@Component({template: '<span #test></span>'})
export class MyComp {
@${queryType}('test') query: any;
get myProperty() { return null; }
// Usually the decorator is set on the get accessor, but it's also possible
// to declare the input on the setter. This ensures that it is handled properly.
@Input()
set myProperty(val: any) {
this.query.test();
}
}
`);
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`@${queryType}('test', { static: true }) query: any;`);
});
示例7: runMigration
it('should add a todo if query options cannot be migrated inline', async() => {
writeFile('/index.ts', `
import {Component, NgModule, ViewChild} from '@angular/core';
const myOptionsVar = {};
@Component({template: '<p #myRef></p>'})
export class MyComp {
@ViewChild('myRef', myOptionsVar) query: any;
}
@NgModule({declarations: [MyComp]})
export class MyModule {}
`);
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`@ViewChild('myRef', /* TODO: add static flag */ myOptionsVar) query: any;`);
expect(warnOutput.length).toBe(1);
expect(warnOutput[0])
.toMatch(/^⎠{3}index.ts@8:11: Cannot update query declaration to explicit timing./);
expect(warnOutput[0]).toMatch(/Please manually set the query timing to.*static: true/);
});
示例8: myProp
it('should not mark queries as static if a value is assigned to accessor property', async() => {
writeFile('/index.ts', `
import {Component, ${queryType}} from '@angular/core';
@Component({template: '<span #test></span>'})
export class MyComp {
private @${queryType}('test') query: any;
set myProp(value: any) { /* noop */}
get myProp() {
return this.query.myValue;
}
ngOnInit() {
this.myProp = true;
}
}
`);
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`@${queryType}('test', { static: false }) query: any;`);
});