test-fns 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/givenWhenThen.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
type TestInputWithReason = [
|
|
2
|
+
string,
|
|
3
|
+
{
|
|
4
|
+
because: string;
|
|
5
|
+
},
|
|
6
|
+
() => Promise<unknown> | void
|
|
7
|
+
];
|
|
8
|
+
type TestInputWithoutReason = [string, () => Promise<void> | void];
|
|
9
|
+
type TestInput = TestInputWithReason | TestInputWithoutReason;
|
|
1
10
|
interface Describe {
|
|
2
11
|
(desc: string, fn: () => void): void;
|
|
3
12
|
/** Only runs the tests inside this `describe` for the current file */
|
|
@@ -6,11 +15,11 @@ interface Describe {
|
|
|
6
15
|
skip: (desc: string, fn: () => void) => void;
|
|
7
16
|
}
|
|
8
17
|
interface Test {
|
|
9
|
-
(
|
|
18
|
+
(...input: TestInput): void;
|
|
10
19
|
/** Only runs this test for the current file */
|
|
11
|
-
only: (
|
|
20
|
+
only: (...input: TestInput) => void;
|
|
12
21
|
/** Skips running this test */
|
|
13
|
-
skip: (
|
|
22
|
+
skip: (...input: TestInput) => void;
|
|
14
23
|
}
|
|
15
24
|
export declare const given: Describe;
|
|
16
25
|
export declare const when: Describe;
|
package/dist/givenWhenThen.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.then = exports.when = exports.given = void 0;
|
|
4
|
+
const castToJestTestInput = ({ input, prefix, }) => {
|
|
5
|
+
if (input.length === 3)
|
|
6
|
+
return [`${prefix}: ${input[0]}`, input[2]]; // we allow users to specify the reason for code readability, but we dont expose this in the test report to decrease noise. folks can look in the code if they want to know "why"
|
|
7
|
+
return [`${prefix}: ${input[0]}`, input[1]]; // otherwise, its the normal input
|
|
8
|
+
};
|
|
4
9
|
const given = (desc, fn) => describe(`given: ${desc}`, fn);
|
|
5
10
|
exports.given = given;
|
|
6
11
|
exports.given.only = (desc, fn) => describe.only(`given: ${desc}`, fn);
|
|
@@ -9,8 +14,8 @@ const when = (desc, fn) => describe(`when: ${desc}`, fn);
|
|
|
9
14
|
exports.when = when;
|
|
10
15
|
exports.when.only = (desc, fn) => describe.only(`when: ${desc}`, fn);
|
|
11
16
|
exports.when.skip = (desc, fn) => describe.skip(`when: ${desc}`, fn);
|
|
12
|
-
const then = (
|
|
17
|
+
const then = (...input) => test(...castToJestTestInput({ input, prefix: 'then' }));
|
|
13
18
|
exports.then = then;
|
|
14
|
-
exports.then.only = (
|
|
15
|
-
exports.then.skip = (
|
|
19
|
+
exports.then.only = (...input) => test.only(...castToJestTestInput({ input, prefix: 'then' }));
|
|
20
|
+
exports.then.skip = (...input) => test.skip(...castToJestTestInput({ input, prefix: 'then' }));
|
|
16
21
|
//# sourceMappingURL=givenWhenThen.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"givenWhenThen.js","sourceRoot":"","sources":["../src/givenWhenThen.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"givenWhenThen.js","sourceRoot":"","sources":["../src/givenWhenThen.ts"],"names":[],"mappings":";;;AAOA,MAAM,mBAAmB,GAAG,CAAC,EAC3B,KAAK,EACL,MAAM,GAIP,EAA4D,EAAE;IAC7D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,iLAAiL;IACtP,OAAO,CAAC,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kCAAkC;AACjF,CAAC,CAAC;AAqBK,MAAM,KAAK,GAAa,CAC7B,IAAY,EACZ,EAA8B,EACxB,EAAE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AAI,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -16,6 +16,15 @@ describe('doesPlantNeedWater', () => {
|
|
|
16
16
|
throw new Error('should have been skipped');
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
|
+
(0, givenWhenThen_1.when)('the plant has enough water', () => {
|
|
20
|
+
const plant = {
|
|
21
|
+
id: 7,
|
|
22
|
+
hydration: 'WET',
|
|
23
|
+
};
|
|
24
|
+
(0, givenWhenThen_1.then)('it should return false', { because: 'because it has enough water' }, () => {
|
|
25
|
+
expect(doesPlantNeedWater(plant)).toEqual(false);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
19
28
|
});
|
|
20
29
|
});
|
|
21
30
|
//# sourceMappingURL=givenWhenThen.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"givenWhenThen.test.js","sourceRoot":"","sources":["../src/givenWhenThen.test.ts"],"names":[],"mappings":";;AAAA,mDAAoD;AAGpD,MAAM,kBAAkB,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC;AAEvE,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAA,qBAAK,EAAC,SAAS,EAAE,GAAG,EAAE;QACpB,IAAA,oBAAI,EAAC,oCAAoC,EAAE,GAAG,EAAE;YAC9C,MAAM,KAAK,GAAU;gBACnB,EAAE,EAAE,CAAC;gBACL,SAAS,EAAE,KAAK;aACjB,CAAC;YACF,IAAA,oBAAI,EAAC,uBAAuB,EAAE,GAAG,EAAE;gBACjC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;YACH,oBAAI,CAAC,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;gBACzD,MAAM,IAAI,KAA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C;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "test-fns",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "write usecase driven tests systematically for simpler, safer, and more readable code",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.1.1",
|
|
6
6
|
"repository": "ehmpathy/test-fns",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/test-fns",
|
|
8
8
|
"keywords": [
|