forked from help-me-mom/ng-mocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MockRender): the host element doesn't have __ngContext__ attribu…
…te anymore help-me-mom#3811 NOTE: If you use jest snapshots it might require to update them and remove the `__ngContext__` attribute from `mock-render` nodes.
- Loading branch information
Showing
7 changed files
with
79 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ rules: | |
body-max-line-length: | ||
- 2 | ||
- always | ||
- 120 | ||
- Infinity | ||
subject-case: | ||
- 0 | ||
- always | ||
|
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 |
---|---|---|
|
@@ -21,4 +21,5 @@ tests-failures/ | |
tmp/ | ||
|
||
**/*.sh | ||
**/*.snap | ||
**/.nvmrc |
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 |
---|---|---|
|
@@ -19,4 +19,5 @@ test-reports/ | |
tmp/ | ||
|
||
**/*.sh | ||
**/*.snap | ||
**/.nvmrc |
21 changes: 21 additions & 0 deletions
21
e2e/jest/src/tests/issue-3811/__snapshots__/test.spec.ts.snap
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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`issue-3811 should render mock-render without __ngContext__ on the first run 1`] = ` | ||
<mock-render> | ||
<hello> | ||
<h1> | ||
Hello Joe! | ||
</h1> | ||
</hello> | ||
</mock-render> | ||
`; | ||
|
||
exports[`issue-3811 should render mock-render without __ngContext__ on the second run 1`] = ` | ||
<mock-render> | ||
<hello> | ||
<h1> | ||
Hello Jane! | ||
</h1> | ||
</hello> | ||
</mock-render> | ||
`; |
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,34 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { MockBuilder, MockRender } from 'ng-mocks'; | ||
|
||
@Component({ | ||
selector: 'hello', | ||
template: `<h1>Hello {{ name }}!</h1>`, | ||
}) | ||
export class HelloComponent { | ||
@Input() public name: string | null = null; | ||
} | ||
|
||
// @see https://github.com/help-me-mom/ng-mocks/issues/3811 | ||
// The problem is that Angular adds `__ngContext__` on the host element (<mock-render>). | ||
// It's an index of the current context: 0, 1, 2, 3. | ||
// So if you have 2 tests, you have 2 contexts, but if you run only 1 test, you have 1 context, | ||
// and, therefore, the snapshot assertion will fail, because the single run has `0` index, whereas in the suite run, | ||
// it can be any other number. | ||
// The solution is to remove __ngContext__ from the snapshot html, so there is no number with the index in it. | ||
// The test below asserts that snapshots don't have __ngContext__ anymore. | ||
describe('issue-3811', () => { | ||
beforeEach(() => { | ||
return MockBuilder(HelloComponent); | ||
}); | ||
|
||
it('should render mock-render without __ngContext__ on the first run', () => { | ||
const fixture = MockRender(HelloComponent, { name: 'Joe' }); | ||
expect(fixture).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render mock-render without __ngContext__ on the second run', () => { | ||
const fixture = MockRender(HelloComponent, { name: 'Jane' }); | ||
expect(fixture).toMatchSnapshot(); | ||
}); | ||
}); |
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,11 @@ | ||
import { MockRender } from 'ng-mocks'; | ||
|
||
// we need to ensure that MockRender component provides correct access to the __ngContext__ property. | ||
describe('issue-3811', () => { | ||
it('provides access to __ngContext__', () => { | ||
const fixture = MockRender(''); | ||
const ngContext = (fixture.componentInstance as any) | ||
.__ngContext__; | ||
expect(ngContext).toBeDefined(); | ||
}); | ||
}); |