-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respecting initialization of providers between tests
closes #186
- Loading branch information
Showing
10 changed files
with
127 additions
and
56 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Injectable, NgModule } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { MockModule } from 'ng-mocks'; | ||
|
||
@Injectable() | ||
class ExampleProvider { | ||
a: number; | ||
} | ||
@NgModule({ | ||
providers: [ExampleProvider], | ||
}) | ||
class ExampleModule {} | ||
|
||
describe('issue-186:real', () => { | ||
let exampleProvider: ExampleProvider; | ||
let exampleProviderFromSetupPhase: ExampleProvider; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ExampleModule], | ||
}); | ||
|
||
exampleProvider = TestBed.get(ExampleProvider); | ||
}); | ||
|
||
it('should not be able to pass state between tests (setup phase)', () => { | ||
exampleProviderFromSetupPhase = exampleProvider; | ||
expect(exampleProvider.a).toBeUndefined(); | ||
exampleProvider.a = 11; | ||
}); | ||
|
||
it('should not be able to pass state between tests (validation phase)', () => { | ||
expect(exampleProvider).not.toBe(exampleProviderFromSetupPhase); | ||
expect(exampleProvider.a).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('issue-186:mock', () => { | ||
let exampleProvider: ExampleProvider; | ||
let exampleProviderFromSetupPhase: ExampleProvider; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MockModule(ExampleModule)], | ||
}); | ||
|
||
exampleProvider = TestBed.get(ExampleProvider); | ||
}); | ||
|
||
it('should not be able to pass state between tests (setup phase)', () => { | ||
exampleProviderFromSetupPhase = exampleProvider; | ||
expect(exampleProvider.a).toBeUndefined(); | ||
exampleProvider.a = 11; | ||
}); | ||
|
||
it('should not be able to pass state between tests (validation phase)', () => { | ||
expect(exampleProvider).not.toBe(exampleProviderFromSetupPhase); | ||
expect(exampleProvider.a).toBeUndefined(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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