-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on #3
- Loading branch information
Showing
4 changed files
with
146 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,84 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { filter } from 'rxjs/operators'; | ||
import { collectionPath } from './common'; | ||
|
||
describe('Calling update on existing specs without setup function', () => { | ||
let tree = Tree.empty(); | ||
|
||
beforeEach(() => { | ||
tree = Tree.empty(); | ||
tree.create( | ||
'c.ts', | ||
`import { LogService, BDep } from '@angular/core'; | ||
export class C { | ||
constructor( | ||
private bDep: bDep, | ||
private logger: LogService | ||
) {} | ||
}` | ||
); | ||
|
||
tree.create( | ||
'c.spec.ts', | ||
`import { bDep } from '@angular/core'; | ||
describe('C', () => { | ||
});` | ||
); | ||
}); | ||
|
||
xit('should pass successfully', () => { | ||
// arrange | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
// act | ||
const errors = []; | ||
runner.logger.pipe(filter(v => v.level === 'error')).subscribe(v => errors.push(v)); | ||
runner.runSchematic('spec', { name: './c.ts', update: true }, tree); | ||
// assert | ||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('should create the setup function and then update it', () => { | ||
// arrange | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
// act | ||
const result = runner.runSchematic('spec', { name: './c.ts', update: true }, tree); | ||
// assert | ||
// @ts-ignore | ||
const contents = result.readContent('./c.spec.ts'); | ||
// update should add LogService to imports, to construct params and create a spy for it | ||
expect(contents).toMatchInlineSnapshot(` | ||
"import { LogService } from '@angular/core'; | ||
import { bDep } from '@angular/core'; | ||
describe('C', () => { | ||
}); | ||
function setup() { | ||
const bDep = autoSpy(bDep); | ||
const logger = autoSpy(LogService); | ||
const builder = { | ||
bDep, | ||
logger, | ||
default() { | ||
return builder; | ||
}, | ||
build() { | ||
return new C(bDep, logger); | ||
} | ||
} | ||
return builder; | ||
}" | ||
`); | ||
}); | ||
}); | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { filter } from 'rxjs/operators'; | ||
import { collectionPath } from './common'; | ||
|
||
describe('Calling update on existing specs without setup function', () => { | ||
let tree = Tree.empty(); | ||
|
||
beforeEach(() => { | ||
tree = Tree.empty(); | ||
tree.create( | ||
'c.ts', | ||
`import { LogService, BDep } from '@angular/core'; | ||
export class C { | ||
constructor( | ||
private aDep: BDep, | ||
private bDep: BDep, | ||
private cDep: BDep, | ||
private logger: LogService | ||
) {} | ||
}` | ||
); | ||
|
||
tree.create( | ||
'c.spec.ts', | ||
`import { bDep } from '@angular/core'; | ||
describe('C', () => { | ||
});` | ||
); | ||
}); | ||
|
||
it('should pass successfully', () => { | ||
// arrange | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
// act | ||
const errors = []; | ||
runner.logger.pipe(filter(v => v.level === 'error')).subscribe(v => errors.push(v)); | ||
runner.runSchematic('spec', { name: './c.ts', update: true }, tree); | ||
// assert | ||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('should indent setup function variable declarations', () => { | ||
// arrange | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
// act | ||
const result = runner.runSchematic('spec', { name: './c.ts', update: true }, tree); | ||
// assert | ||
// @ts-ignore | ||
const contents = result.readContent('./c.spec.ts'); | ||
// update should add LogService to imports, to construct params and create a spy for it | ||
expect(contents).toMatchInlineSnapshot(` | ||
"import { BDep } from '@angular/core'; | ||
import { BDep } from '@angular/core'; | ||
import { BDep } from '@angular/core'; | ||
import { LogService } from '@angular/core'; | ||
import { bDep } from '@angular/core'; | ||
describe('C', () => { | ||
}); | ||
function setup() { | ||
const aDep = autoSpy(BDep); | ||
const bDep = autoSpy(BDep); | ||
const cDep = autoSpy(BDep); | ||
const logger = autoSpy(LogService); | ||
const builder = { | ||
aDep, | ||
bDep, | ||
cDep, | ||
logger, | ||
default() { | ||
return builder; | ||
}, | ||
build() { | ||
return new C(aDep, bDep, cDep, logger); | ||
} | ||
} | ||
return builder; | ||
}" | ||
`); | ||
}); | ||
}); |