mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-15 18:13:38 +08:00
test(@schematics/angular): update several tests to use async expectations
Using Jasmine's `expectAsync` allows for reduced test code when testing that a function returning a promise rejects with a specific error.
This commit is contained in:
parent
e81a6f1c46
commit
bb43e0a7c4
@ -159,13 +159,10 @@ describe('Component Schematic', () => {
|
||||
|
||||
it('should fail if specified module does not exist', async () => {
|
||||
const options = { ...defaultOptions, module: '/projects/bar/src/app.moduleXXX.ts' };
|
||||
let thrownError: Error | null = null;
|
||||
try {
|
||||
await schematicRunner.runSchematicAsync('component', options, appTree).toPromise();
|
||||
} catch (err) {
|
||||
thrownError = err;
|
||||
}
|
||||
expect(thrownError).toBeDefined();
|
||||
|
||||
await expectAsync(
|
||||
schematicRunner.runSchematicAsync('component', options, appTree).toPromise(),
|
||||
).toBeRejected();
|
||||
});
|
||||
|
||||
it('should handle upper case paths', async () => {
|
||||
|
@ -108,13 +108,10 @@ describe('Directive Schematic', () => {
|
||||
|
||||
it('should fail if specified module does not exist', async () => {
|
||||
const options = { ...defaultOptions, module: '/projects/bar/src/app/app.moduleXXX.ts' };
|
||||
let thrownError: Error | null = null;
|
||||
try {
|
||||
await schematicRunner.runSchematicAsync('directive', options, appTree).toPromise();
|
||||
} catch (err) {
|
||||
thrownError = err;
|
||||
}
|
||||
expect(thrownError).toBeDefined();
|
||||
|
||||
await expectAsync(
|
||||
schematicRunner.runSchematicAsync('directive', options, appTree).toPromise(),
|
||||
).toBeRejected();
|
||||
});
|
||||
|
||||
it('should converts dash-cased-name to a camelCasedSelector', async () => {
|
||||
|
@ -72,13 +72,10 @@ describe('Pipe Schematic', () => {
|
||||
|
||||
it('should fail if specified module does not exist', async () => {
|
||||
const options = { ...defaultOptions, module: '/projects/bar/src/app/app.moduleXXX.ts' };
|
||||
let thrownError: Error | null = null;
|
||||
try {
|
||||
await schematicRunner.runSchematicAsync('pipe', options, appTree).toPromise();
|
||||
} catch (err) {
|
||||
thrownError = err;
|
||||
}
|
||||
expect(thrownError).toBeDefined();
|
||||
|
||||
await expectAsync(
|
||||
schematicRunner.runSchematicAsync('pipe', options, appTree).toPromise(),
|
||||
).toBeRejected();
|
||||
});
|
||||
|
||||
it('should handle a path in the name and module options', async () => {
|
||||
|
@ -43,34 +43,24 @@ describe('find-module', () => {
|
||||
|
||||
it('should throw if no modules found', () => {
|
||||
host.create('/foo/src/app/oops.module.ts', 'app module');
|
||||
try {
|
||||
findModule(host, 'foo/src/app/bar');
|
||||
throw new Error('Succeeded, should have failed');
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/More than one module matches/);
|
||||
}
|
||||
|
||||
expect(() => findModule(host, 'foo/src/app/bar')).toThrowError(
|
||||
/More than one module matches/,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if only routing modules were found', () => {
|
||||
host = new EmptyTree();
|
||||
host.create('/foo/src/app/anything-routing.module.ts', 'anything routing module');
|
||||
|
||||
try {
|
||||
findModule(host, 'foo/src/app/anything-routing');
|
||||
throw new Error('Succeeded, should have failed');
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/Could not find a non Routing NgModule/);
|
||||
}
|
||||
expect(() => findModule(host, 'foo/src/app/anything-routing')).toThrowError(
|
||||
/Could not find a non Routing NgModule/,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if two modules found', () => {
|
||||
try {
|
||||
host = new EmptyTree();
|
||||
findModule(host, 'foo/src/app/bar');
|
||||
throw new Error('Succeeded, should have failed');
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/Could not find an NgModule/);
|
||||
}
|
||||
host = new EmptyTree();
|
||||
expect(() => findModule(host, 'foo/src/app/bar')).toThrowError(/Could not find an NgModule/);
|
||||
});
|
||||
|
||||
it('should accept custom ext for module', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user