Skip to content

Commit 1f7ea27

Browse files
committed
feat: add only feature to use fdescribe
1 parent a26ef96 commit 1f7ea27

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

library/global-config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const NO_FRAMEWORK_ADAPTER_ERROR = () => {
88

99
const DEFAULT_TESTING_FRAMEWORK_ADAPTER = {
1010
describe: NO_FRAMEWORK_ADAPTER_ERROR,
11+
fdescribe: NO_FRAMEWORK_ADAPTER_ERROR,
1112
beforeEach: NO_FRAMEWORK_ADAPTER_ERROR,
1213
};
1314

library/scenario-testing/scenario-testing.ts

+26-9
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ export class NgtxScenarioTestEnvironment<T> {
5656

5757
public run() {
5858
const { _framework, _moduleConfig, _componentType, scenarios } = this;
59-
const { describe, beforeEach } = _framework;
59+
const { describe, fdescribe, beforeEach } = _framework;
6060

6161
for (const scenario of scenarios) {
62-
describe(scenario['_description'], () => {
62+
const descriptor = scenario['_runFocused'] ? fdescribe : describe;
63+
64+
descriptor(scenario['_description'], () => {
6365
beforeEach(async () => {
6466
await TestBed.configureTestingModule(
6567
_moduleConfig,
@@ -84,6 +86,7 @@ export class NgtxTestScenario<T = any> {
8486
): NgtxTestScenario<T> {
8587
return new NgtxTestScenario(
8688
props.description,
89+
props.runFocused,
8790
environment,
8891
props.moduleConfig,
8992
props.componentType,
@@ -95,6 +98,7 @@ export class NgtxTestScenario<T = any> {
9598

9699
private constructor(
97100
private readonly _description: string,
101+
private readonly _runFocused: boolean,
98102
private readonly _testEnvironment: NgtxScenarioTestEnvironment<T>,
99103
private readonly _moduleConfig: TestModuleMetadata,
100104
private readonly _componentType: Type<T>,
@@ -113,6 +117,7 @@ export class NgtxTestScenario<T = any> {
113117
{
114118
componentType: this._componentType,
115119
description: this._description,
120+
runFocused: this._runFocused,
116121
moduleConfig: this._moduleConfig,
117122
modificationsBeforeComponentCreation: [
118123
...this._modificationsBeforeComponentCreation,
@@ -137,6 +142,7 @@ export class NgtxTestScenario<T = any> {
137142
{
138143
componentType: this._componentType,
139144
description: this._description,
145+
runFocused: this._runFocused,
140146
moduleConfig: this._moduleConfig,
141147
modificationsBeforeComponentCreation:
142148
this._modificationsBeforeComponentCreation,
@@ -174,16 +180,27 @@ export function useScenarioTesting<T>(
174180
props.componentType,
175181
);
176182

177-
const controlLevelScenario = NgtxTestScenario.from(
178-
{ ...props, description: 'Control' },
179-
environment,
180-
);
181-
const controlLevelExpect: NgtxTestScenario<T>['expect'] =
182-
controlLevelScenario.expect.bind(controlLevelScenario);
183+
let runScenarioFocused = false;
184+
const only = (userScenarios: () => unknown) => {
185+
runScenarioFocused = true;
186+
userScenarios();
187+
runScenarioFocused = false;
188+
};
189+
190+
const controlLevelExpect: NgtxTestScenario<T>['expect'] = (...scenarios) => {
191+
return NgtxTestScenario.from(
192+
{ ...props, runFocused: runScenarioFocused, description: 'Control' },
193+
environment,
194+
).expect(...scenarios);
195+
};
183196

184197
return {
198+
only,
185199
scenario: (description: string) =>
186-
NgtxTestScenario.from({ ...props, description }, environment),
200+
NgtxTestScenario.from(
201+
{ ...props, runFocused: runScenarioFocused, description },
202+
environment,
203+
),
187204
expect: controlLevelExpect,
188205
tests: environment,
189206
};

library/scenario-testing/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type ScenarioTestDefinition<T> = (
1111
fixtureRef: ComponentFixtureRef<T>,
1212
) => void;
1313
export type NgtxTestingFrameworkAdapter = {
14+
fdescribe: (title: string, suite: () => void) => void;
1415
describe: (title: string, suite: () => void) => void;
1516
beforeEach: (fn: () => void) => void;
1617
};
@@ -21,6 +22,7 @@ export type NgtxScenarioInitProps<T> = {
2122
};
2223

2324
export type NgtxScenarioProps<T> = NgtxScenarioInitProps<T> & {
25+
runFocused: boolean;
2426
description: string;
2527
tests?: ScenarioTestDefinition<T>[];
2628
modificationsBeforeComponentCreation?: ScenarioSetupFn[];

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@centigrade/ngtx",
3-
"version": "2.6.0-alpha.9",
3+
"version": "2.6.0-alpha.10",
44
"description": "The Angular Testing Extensions is a small set of functions, aiming to make your life easier, when testing Angular components.",
55
"scripts": {
66
"clean": "shx rm -rf dist",

setupAngularTestEnv.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ setupZoneTestEnv();
66

77
const jestFramework: NgtxTestingFrameworkAdapter = {
88
describe,
9+
fdescribe,
910
beforeEach,
1011
};
1112

0 commit comments

Comments
 (0)