Skip to content

Commit 0af6018

Browse files
feat: add global excludeComponentDeclaration (#194)
1 parent 38e15cc commit 0af6018

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

projects/testing-library/src/lib/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Config } from './models';
22

33
let config: Config = {
4-
defaultImports: [],
54
dom: {},
5+
defaultImports: [],
66
};
77

88
export function configure(newConfig: Partial<Config> | ((config: Partial<Config>) => Partial<Config>)) {

projects/testing-library/src/lib/models.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,14 @@ export interface RenderDirectiveOptions<WrapperType, Properties extends object =
281281
componentProperties?: Partial<WrapperType & Properties>;
282282
}
283283

284-
export interface Config {
285-
defaultImports: any[];
284+
export interface Config extends Pick<RenderComponentOptions<any>, 'excludeComponentDeclaration'> {
285+
/**
286+
* DOM Testing Library config
287+
* @link https://testing-library.com/docs/dom-testing-library/api-configuration/
288+
*/
286289
dom: Partial<dtlConfig>;
290+
/**
291+
* Imports that are added to the imports
292+
*/
293+
defaultImports: any[];
287294
}

projects/testing-library/src/lib/testing-library.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function render<SutType, WrapperType = SutType>(
4141
sut: Type<SutType>,
4242
renderOptions: RenderComponentOptions<SutType> | RenderDirectiveOptions<WrapperType> = {},
4343
): Promise<RenderResult<SutType>> {
44+
const { dom: domConfig, ...globalConfig } = getConfig();
4445
const {
4546
detectChanges: detectChangesOnRender = true,
4647
declarations = [],
@@ -55,22 +56,24 @@ export async function render<SutType, WrapperType = SutType>(
5556
excludeComponentDeclaration = false,
5657
routes,
5758
removeAngularAttributes = false,
58-
} = renderOptions as RenderDirectiveOptions<WrapperType>;
59-
60-
const config = getConfig();
59+
defaultImports = [],
60+
} = { ...globalConfig, ...renderOptions };
6161

6262
dtlConfigure({
6363
eventWrapper: (cb) => {
6464
const result = cb();
6565
detectChangesForMountedFixtures();
6666
return result;
6767
},
68-
...config.dom,
68+
...domConfig,
6969
});
7070

7171
TestBed.configureTestingModule({
7272
declarations: addAutoDeclarations(sut, { declarations, excludeComponentDeclaration, template, wrapper }),
73-
imports: addAutoImports({ imports: imports.concat(config.defaultImports), routes }),
73+
imports: addAutoImports({
74+
imports: imports.concat(defaultImports),
75+
routes,
76+
}),
7477
providers: [...providers],
7578
schemas: [...schemas],
7679
});

projects/testing-library/tests/render.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('animationModule', () => {
5555
})
5656
class FixtureModule {}
5757
describe('excludeComponentDeclaration', () => {
58-
test('will throw if component is declared in an import', async () => {
58+
test('does not throw if component is declared in an imported module', async () => {
5959
await render(FixtureComponent, {
6060
imports: [FixtureModule],
6161
excludeComponentDeclaration: true,

0 commit comments

Comments
 (0)