risei 1.1.1 → 1.2.0

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.
Files changed (45) hide show
  1. package/README.md +17 -16
  2. package/index.js +1 -1
  3. package/package.json +6 -5
  4. package/system/Risei.js +1 -1
  5. package/system/TestFinder.js +19 -3
  6. package/system/TestRunner.js +1 -1
  7. package/tests/other-tests/ASpoofingFixture.tests.js +0 -242
  8. package/tests/other-tests/SpoofClassesFixture.tests.js +0 -130
  9. package/tests/other-tests/SpoofObjectsFixture.tests.js +0 -95
  10. package/tests/other-tests/SpoofTuple.tests.js +0 -93
  11. package/tests/other-tests/TotalComparer.tests.js +0 -920
  12. package/tests/other-tests/package.json +0 -7
  13. package/tests/risei-tests/ASpoofingFixtureTests.rt.js +0 -51
  14. package/tests/risei-tests/MomentTests.rt.js +0 -103
  15. package/tests/risei-tests/SpoofTupleTests.rt.js +0 -274
  16. package/tests/risei-tests/TestFrameChooserTests.rt.js +0 -74
  17. package/tests/risei-tests/TestFrameTests.rt.js +0 -84
  18. package/tests/risei-tests/TestStagesTests.rt.js +0 -99
  19. package/tests/risei-tests/TestTupleTests.rt.js +0 -140
  20. package/tests/risei-tests/TotalComparerTests.rt.js +0 -184
  21. package/tests/risei-tests/TotalCopierTests.rt.js +0 -74
  22. package/tests/risei-tests/TotalDisplayerTests.rt.js +0 -186
  23. package/tests/risei-tests/TypeAnalyzerTests.rt.js +0 -29
  24. package/tests/risei-tests/TypeIdentifierTests.rt.js +0 -44
  25. package/tests/self-tests/SelfTests.outward-rt.js +0 -583
  26. package/tests/target-objects/CompositionModel.js +0 -38
  27. package/tests/target-objects/ConditionalThrowModel.js +0 -11
  28. package/tests/target-objects/CountModel.js +0 -46
  29. package/tests/target-objects/DomModel.js +0 -37
  30. package/tests/target-objects/MixedContents.js +0 -33
  31. package/tests/target-objects/MutationModel.js +0 -27
  32. package/tests/target-objects/ObjectCompositionModel.js +0 -34
  33. package/tests/target-objects/PolySpoofableInner.js +0 -30
  34. package/tests/target-objects/PolySpoofableOuter.js +0 -52
  35. package/tests/target-objects/PropertiesModel.js +0 -47
  36. package/tests/target-objects/Returner.js +0 -9
  37. package/tests/target-objects/SearchModel.js +0 -25
  38. package/tests/target-objects/SortModel.js +0 -91
  39. package/tests/target-objects/SpoofCaller.js +0 -24
  40. package/tests/target-objects/Spoofable.js +0 -36
  41. package/tests/target-objects/SpoofableArgsCaller.js +0 -33
  42. package/tests/target-objects/StateModel.js +0 -34
  43. package/tests/target-objects/StaticModel.js +0 -17
  44. package/tests/target-objects/TestableModel.js +0 -47
  45. package/tests/topic-tests/TopicTests.outward-rt.js +0 -354
package/README.md CHANGED
@@ -8,11 +8,7 @@
8
8
  * Refactor or replace existing designs without worrying about the cost in past or future test time.
9
9
  * Create tests with immediate confidence, because you can't introduce mistakes in test code you write.
10
10
 
11
- > Risei is under active development.  To see the latest changes, check out [What's new in Risei](#whats-new-in-risei).
12
- >
13
- > For a list of any known bugs and workarounds, see [Known bugs and workarounds](#known-bugs-and-workarounds).  To see which JavaScript features Risei doesn't address yet, check out [Limitations in Risei](#limitations-in-risei).
14
-
15
- Risei may be referred to as **Rs** here for brevity.  A dotted `.name` here means a property, just like a `name()` with parens is a method or function.
11
+ Risei may be referred to as **Rs** here for brevity.
16
12
 
17
13
 
18
14
 
@@ -31,9 +27,12 @@ Here is the terminal output of these two example tests.  Tests are grouped
31
27
  ![https://deusware.com/Output-example.png](https://deusware.com/Output-example.png)
32
28
 
33
29
 
34
- An individual test may appear on one line or multiple lines, depending on how wide the terminal window is.  Any failing tests appear in light red. 
30
+ - An individual test may appear on one line or multiple lines, depending on how wide the terminal window is.
31
+ - Any failing tests appear in light red.
32
+ - Your latest-edited tests always sort to the bottom, so you can see your current test results at a glance.
33
+
35
34
 
36
- Test runs also feature a title bar, as well as a summary bar at the bottom:
35
+ Test runs also feature a title bar at the top, as well as a summary bar at the bottom:
37
36
 
38
37
  ![https://deusware.com/Summary-example.png](https://deusware.com/Summary-example.png)
39
38
 
@@ -42,6 +41,8 @@ Test runs also feature a title bar, as well as a summary bar at the bottom:
42
41
 
43
42
  ## Using Risei
44
43
 
44
+ Risei is under active development.  If you've been here before, check out [what's new in Risei](#whats-new-in-risei) for the latest.  Also see [known bugs and workarounds](#known-bugs-and-workarounds) and [limitations in Risei](#limitations-in-risei).
45
+
45
46
  ### Installation
46
47
 
47
48
  Install Risei for development time only:
@@ -160,9 +161,7 @@ Or write a `package.json` script that does the same:
160
161
 
161
162
  ```json
162
163
  "scripts": {
163
- ...
164
- "test": "node ./node_modules/risei/index.js",
165
- ...
164
+ "test": "node ./node_modules/risei/index.js"
166
165
  }
167
166
  ```
168
167
 
@@ -475,8 +474,7 @@ Most problems with using Risei are minor mistakes in syntax, or omissions in tes
475
474
  | `"Test loading failed for... SyntaxError: Unexpected token ':'"` | Missing comma in your tests in the named file |
476
475
  | `"Test loading failed for... SyntaxError: Unexpected token '.'"` | Using `this.tests = []` instead of `tests = []` in the file named |
477
476
  | Other `... Unexpected token ...` errors | Some other syntax error in the file named, most likely a missing or extra delimiter |
478
- | Unexpected actual values, or unexpected passes / fails in test runs | Spoofs, retrievals, or special conditions from previous tests not replaced or reset with `[ ]`<br>&mdash; or &mdash;<br>Tested method mutates `.in` or `.with` args: preventable by using a function to supply those args<br>&mdash; or &mdash;<br>Pre-listed test properties produce extra tests: preventable by restating class in `.on`
479
- |
477
+ | Unexpected actual values, or unexpected passes / fails in test runs | Spoofs, retrievals, or special conditions from previous tests not replaced or reset with `[ ]`<br>&mdash; or &mdash;<br>Tested method mutates `.in` or `.with` args: preventable by using a function to supply those args<br>&mdash; or &mdash;<br>Pre-listed test properties produce extra tests: preventable by restating class in `.on` |
480
478
 
481
479
 
482
480
 
@@ -507,12 +505,15 @@ One known unexpected result (not quite a bug) exists:
507
505
 
508
506
  ## What's new in Risei
509
507
 
510
- Release **1.1.1** of Risei (January, 2024) fixes two problems:
511
- - Classes were sometimes displayed in output as their entire definition, instead of just the class name.
512
- - All `Date` instances were considered equal, regardless of their actual value.
508
+ - Release **1.2.0** (January, 2024) changes sorting of test files.&nbsp; Previously they were displayed in the order found.&nbsp; Now the last-edited file is moved to the bottom, making it easy to see the latest test results.
509
+
510
+
511
+ - Release **1.1.2** of Risei (January, 2024) fixes two problems:
512
+ - Classes were sometimes displayed in output as their entire definition.&nbsp; Now just the class name is displayed.
513
+ - All `Date` instances were considered equal, regardless of their actual value.&nbsp; Now they only are considered equal when they actually are.
513
514
 
514
- Development of Risei is ongoing, including internal improvements, problem fixes, and additional options for testing.
515
515
 
516
+ > Don't use release **1.1.1**, which contains an internal path error.
516
517
 
517
518
 
518
519
 
package/index.js CHANGED
@@ -66,7 +66,7 @@ let wide = (text) => {
66
66
  async function runRiseiTests(testFinderPath) {
67
67
  // region Converting test-finder from path to class
68
68
 
69
- testFinderPath = testFinderPath || "./public/javascript/TestFinder.js";
69
+ testFinderPath = testFinderPath || "./system/TestFinder.js";
70
70
  let finderModule = await import(testFinderPath);
71
71
 
72
72
  let moduleKeys = Object.keys(finderModule);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "risei",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Risei is the framework that allows you to write unit tests as collections of values in JavaScript objects, so it's easy and fast, and tests don't serve as a drag on redesigns.",
5
5
  "keywords": [
6
6
  "unit test",
@@ -28,11 +28,12 @@
28
28
  "test": "clear; node ./node_modules/risei/index.js"
29
29
  },
30
30
  "risei": {
31
- "tests": "**.rt.js"
31
+ "tests": "**.rt.js",
32
+ "sort": "normal"
32
33
  },
33
34
  "exports": {
34
35
  ".": "./index.js",
35
- "./ATestSource": "./public/javascript/ATestSource.js"
36
+ "./ATestSource": "./system/ATestSource.js"
36
37
  },
37
38
  "dependencies": {
38
39
  "chalk": "^5.0.0",
@@ -44,10 +45,10 @@
44
45
  "chalk": "^5.0.0",
45
46
  "cookie-parser": "~1.4.4",
46
47
  "debug": "~2.6.9",
47
- "express": "~4.16.1",
48
+ "express": "^4.18.2",
48
49
  "fs": "^0.0.1-security",
49
50
  "mocha": "^10.0.0",
50
51
  "morgan": "~1.9.1",
51
- "risei": "^1.1.0"
52
+ "risei": "1.1.2"
52
53
  }
53
54
  }
package/system/Risei.js CHANGED
@@ -69,7 +69,7 @@ console.log();
69
69
 
70
70
  // Test-system objects and their relationships.
71
71
  const finder = new ChosenTestFinder();
72
- const runner = new TestRunner(finder.findAllTests());
72
+ const runner = new TestRunner();
73
73
  const reporter = new TerminalReporter();
74
74
 
75
75
  const caller = new LocalCaller(finder, runner, reporter);
@@ -35,12 +35,14 @@ export class TestFinder extends ATestFinder {
35
35
  let source = this.sourceBySearch();
36
36
  this.#sought = source.tests;
37
37
  let testPaths = this.pathsFromTargetingSource();
38
-
38
+
39
+ testPaths = this.sortTestPaths(testPaths);
40
+
39
41
  let tests = [];
40
42
 
41
43
  for (let testPath of testPaths) {
42
44
  // Contents of test sources have to be loaded.
43
- let sources = await this.convertPathToClassInstances(testPath);
45
+ let sources = await this.convertPathToClassInstances(testPath.path);
44
46
 
45
47
  // Any test classes in each source have to be loaded.
46
48
  for (let source of sources) {
@@ -99,7 +101,9 @@ export class TestFinder extends ATestFinder {
99
101
  // This level: any test files.
100
102
  if (entry.isFile()) {
101
103
  if (minimatch(entry.path, this.#sought, { matchBase: true })) {
102
- paths.push(entry.path);
104
+ // Test file's last-edited time stored with path for some sortings.
105
+ let stats = fs.statSync(entry.path);
106
+ paths.push({ path: entry.path, changed: stats.mtimeMs });
103
107
  }
104
108
  }
105
109
 
@@ -110,6 +114,18 @@ export class TestFinder extends ATestFinder {
110
114
  }
111
115
  }
112
116
 
117
+ sortTestPaths(testPaths) /* passed */ {
118
+ // Latest is found for placing at end.
119
+ let latest = testPaths.reduce((prior, now) => { return now.changed > prior.changed ? now : prior; });
120
+
121
+ // Copy made with latest removed, which is added at end.
122
+ let sorted = testPaths.filter(x => x !== latest);
123
+ sorted.push(latest);
124
+
125
+ // Back to caller.
126
+ return sorted;
127
+ }
128
+
113
129
  async convertPathToClassInstances(classPath) {
114
130
  // Each test source may have multiple test classes.
115
131
  let testSources = [];
@@ -259,7 +259,7 @@ export class TestRunner {
259
259
  this.#numberFailed++;
260
260
  }
261
261
 
262
- this.#allDidPass &= test.didPass;
262
+ this.#allDidPass &&= test.didPass;
263
263
  }
264
264
 
265
265
  // endregion Dependencies of runOneTest()
@@ -1,242 +0,0 @@
1
- /**/
2
-
3
- import { ASpoofingFixture } from "../../system/ASpoofingFixture.js";
4
- import { SpoofTuple } from "../../system/SpoofTuple.js";
5
- import { TotalComparer } from "../../system/TotalComparer.js";
6
- import { expect } from "chai";
7
-
8
- describe("ASpoofingFixture", () => {
9
- /* All the tests here are valid as long as TotalComparer
10
- and any linked objects are passing all their tests. */
11
- let comparer = new TotalComparer();
12
-
13
- /* Some cases here are effectively impossible to test directly in self-tests, at least
14
- without complicated workarounds, because of how SpoofTuple is used by Kitten tests. */
15
-
16
- describe("spoofMethod()", () => {
17
- describe("Direct tests: Definition of spoofed method is compared.", () => {
18
- it("Should return an empty method when not provided an arg.", /* good */ () => {
19
- let target = new ASpoofingFixture();
20
-
21
- let expected = () => { };
22
-
23
- let actual = target.spoofMethod();
24
-
25
- let comparison = comparer.compare(expected, actual);
26
- expect(comparison).to.be.true;
27
- });
28
-
29
- it("Should return an empty method when not provided undefined as arg.", /* good */ () => {
30
- let target = new ASpoofingFixture();
31
-
32
- let expected = () => { };
33
-
34
- let actual = target.spoofMethod(undefined);
35
-
36
- let comparison = comparer.compare(expected, actual);
37
- expect(comparison).to.be.true;
38
- });
39
-
40
- it("Should return any whole function supplied as arg.", /* good */ () => {
41
- let target = new ASpoofingFixture();
42
-
43
- let expected = () => {
44
- let sum = 6 + 5;
45
- console.log(sum);
46
- };
47
-
48
- let actual = target.spoofMethod(expected);
49
-
50
- let comparison = comparer.compare(expected, actual);
51
- expect(comparison).to.be.true;
52
- });
53
-
54
- it("Should return a simple method naming the parameter when any non-function arg supplied.", /* good */ () => {
55
- let target = new ASpoofingFixture();
56
-
57
- let expected = () => { return spoofOutput; };
58
-
59
- let actual = target.spoofMethod(778);
60
-
61
- let comparison = comparer.compare(expected, actual);
62
- expect(comparison).to.be.true;
63
- });
64
- });
65
-
66
- describe("Indirect tests: Result of calling spoofed method is tested.", () => {
67
- it("Should return a simple method returning any value supplied as arg.", /* good */ () => {
68
- let target = new ASpoofingFixture();
69
-
70
- let expected = 322;
71
-
72
- let spoofed = target.spoofMethod(322);
73
- let actual = spoofed();
74
-
75
- let comparison = comparer.compare(expected, actual);
76
- expect(comparison).to.be.true;
77
- });
78
-
79
- it("Should return a simple method returning any string supplied as arg.", /* good */ () => {
80
- let target = new ASpoofingFixture();
81
-
82
- let expected = "A short text.";
83
-
84
- let spoofed = target.spoofMethod("A short text.");
85
- let actual = spoofed();
86
-
87
- let comparison = comparer.compare(expected, actual);
88
- expect(comparison).to.be.true;
89
- });
90
-
91
- it("Should return a simple method returning any object supplied as arg.", /* good */ () => {
92
- let target = new ASpoofingFixture();
93
-
94
- let expected = { first: "a", second: 2, third: "C" };
95
-
96
- let spoofed = target.spoofMethod({ first: "a", second: 2, third: "C" });
97
- let actual = spoofed();
98
-
99
- let comparison = comparer.compare(expected, actual);
100
- expect(comparison).to.be.true;
101
- });
102
-
103
- it("Should return a simple method returning any specialized object supplied as arg.", /* good */ () => {
104
- let target = new ASpoofingFixture();
105
-
106
- let expected = new Map([[1, "g"], [2, "k"]]);
107
-
108
- let spoofed = target.spoofMethod(new Map([[1, "g"], [2, "k"]]));
109
- let actual = spoofed();
110
-
111
- let comparison = comparer.compare(expected, actual);
112
- expect(comparison).to.be.true;
113
- });
114
-
115
- it("Should return a simple method returning any deep object supplied as arg", /* good */ () => {
116
- let target = new ASpoofingFixture();
117
- let arg = { these: { those: { the: { other: () => { return 44; } } } } };
118
-
119
- let spoofed = target.spoofMethod(arg);
120
- let actual = spoofed();
121
-
122
- let expected = { these: { those: { the: { other: () => { return 44; } } } } };
123
-
124
- let comparison = comparer.compare(expected, actual);
125
- expect(comparison).to.be.true;
126
- });
127
-
128
- it("Should return a simple method returning any deep spoofed object defined in the arg.", /* good */ () => {
129
- let target = new ASpoofingFixture();
130
- let arg = [ { of: "these.those.the.other", as: 76 } ];
131
-
132
- let spoofed = target.spoofMethod(arg);
133
- let actual = spoofed();
134
-
135
- let expected = { these: { those: { the: { other: () => { return spoofOutput; } } } } };
136
-
137
- let comparison = comparer.compare(actual, expected);
138
- expect(comparison).to.be.true;
139
- });
140
-
141
- });
142
- });
143
-
144
- describe("spoofObjectTree()", () => {
145
- it("Should return (object(empty method)) when given one part and no output.", /* good */ () => {
146
- let target = new ASpoofingFixture();
147
- let arg = [{ of: "action" }];
148
-
149
- let expected = { action: () => { } };
150
-
151
- let actual = target.spoofObjectTree(arg);
152
-
153
- let comparison = comparer.compare(expected, actual);
154
- expect(comparison).to.be.true;
155
- });
156
-
157
- it("Should return (object(object(empty method))) when given two parts and no output.", /* good */ () => {
158
- let target = new ASpoofingFixture();
159
- let arg = [{ of: "thing.action" }];
160
-
161
- let expected = { thing: { action: () => { } } };
162
-
163
- let actual = target.spoofObjectTree(arg);
164
-
165
- let comparison = comparer.compare(expected, actual);
166
- expect(comparison).to.be.true;
167
- });
168
-
169
- it("Should return (object(object(object(empty method)))) when given three parts and no output.", /* good */ () => {
170
- let target = new ASpoofingFixture()
171
- let arg = [{ of: "outer.inner.action" }];
172
-
173
- let expected = { outer: { inner: { action: () => { } } } };
174
-
175
- let actual = target.spoofObjectTree(arg);
176
-
177
- let comparison = comparer.compare(expected, actual);
178
- expect(comparison).to.be.true;
179
- });
180
-
181
- it("Should return (object(value-returning method)) when given one part and an output value.", /* good */ () => {
182
- let target = new ASpoofingFixture();
183
- let arg = [{ of: "ten", as: 10 }];
184
-
185
- let expected = { ten: () => { return spoofOutput; } };
186
-
187
- let actual = target.spoofObjectTree(arg);
188
-
189
- let comparison = comparer.compare(expected, actual);
190
- expect(comparison).to.be.true;
191
- });
192
-
193
- it("Should return (object(object(value-returning method))) when given two parts and an output value.", /* good */ () => {
194
- let target = new ASpoofingFixture();
195
- let arg = [{ of: "thing.eleven", as: 11 }];
196
-
197
- let expected = { thing: { eleven: () => { return spoofOutput; } } };
198
-
199
- let actual = target.spoofObjectTree(arg);
200
-
201
- let comparison = comparer.compare(expected, actual);
202
- expect(comparison).to.be.true;
203
- });
204
-
205
- it("Should return (object(object(object(value-returning method)))) when given three parts and an output value.", /* good */ () => {
206
- let target = new ASpoofingFixture();
207
- let arg = [{ of: "outer.inner.twelve", as: 12 }];
208
-
209
- let expected = { outer: { inner: { twelve: () => { return spoofOutput; } } } };
210
-
211
- let actual = target.spoofObjectTree(arg);
212
-
213
- let comparison = comparer.compare(expected, actual);
214
- expect(comparison).to.be.true;
215
- });
216
-
217
- it("Should return (object(object(string-returning method))) when given two parts and an output string.", /* good */ () => {
218
- let target = new ASpoofingFixture();
219
- let arg = [{ of: "thing.outputText", as: "text-output" }];
220
-
221
- let expected = { thing: { outputText: () => { return spoofOutput; } } };
222
-
223
- let actual = target.spoofObjectTree(arg);
224
-
225
- let comparison = comparer.compare(expected, actual);
226
- expect(comparison).to.be.true;
227
- });
228
-
229
- it("Should return (object(object(nonce method))) when given two parts and a nonce method.", /* good */ () => {
230
- let target = new ASpoofingFixture();
231
- let arg = [{ of: "thing.sumIsFourteen", as: () => { return 11 + 3; } }];
232
-
233
- let expected = { thing: { sumIsFourteen: () => { return 11 + 3; } } };
234
-
235
- let actual = target.spoofObjectTree(arg);
236
-
237
- let comparison = comparer.compare(expected, actual);
238
- expect(comparison).to.be.true;
239
- });
240
-
241
- });
242
- });
@@ -1,130 +0,0 @@
1
- /**/
2
-
3
- import { SpoofClassMethodsFixture } from "../../system/SpoofClassMethodsFixture.js";
4
- import { Spoofable } from "../target-objects/Spoofable.js";
5
- import { TotalComparer } from "../../system/TotalComparer.js";
6
-
7
- import { expect } from "chai";
8
-
9
- describe("SpoofClassMethodsFixture", () => {
10
- let comparer = new TotalComparer();
11
-
12
- describe("spoof()", () => {
13
- describe("Direct tests: Definition of spoofed method is compared.", () => {
14
- it("Should set class method to be empty when given args which define that.", /* good */ () => {
15
- let target = new SpoofClassMethodsFixture();
16
- let definition = { of: "spoofNumber" };
17
- let arg = { on: Spoofable, plus: [ definition ] };
18
-
19
- target.spoof(arg);
20
-
21
- let actual = Spoofable.prototype.spoofNumber;
22
-
23
- target.unspoof();
24
-
25
- let comparison = comparer.compare(actual, () => { });
26
- expect(comparison).to.be.true;
27
- });
28
-
29
- it("Should set class method to a known nonce function when given that nonce as an arg.", /* good */ () => {
30
- let target = new SpoofClassMethodsFixture();
31
- let definition = { of: "spoofNumber", as: (a, b) => { return b - a; } };
32
- let arg = { on: Spoofable, plus: [ definition ] };
33
-
34
- target.spoof(arg);
35
-
36
- let actual = Spoofable.prototype.spoofNumber;
37
-
38
- target.unspoof();
39
-
40
- let comparison = comparer.compare(actual, (a, b) => { return b - a; });
41
- expect(comparison).to.be.true;
42
- });
43
-
44
- it("Should set class method to a simple function returning a named parameter when given args which define that.", /* good */ () => {
45
- let target = new SpoofClassMethodsFixture();
46
- let definition = { of: "spoofNumber" , as: 32 };
47
- let arg = { on: Spoofable, plus: [ definition ] };
48
-
49
- target.spoof(arg);
50
-
51
- let actual = Spoofable.prototype.spoofNumber;
52
-
53
- target.unspoof();
54
-
55
- let comparison = comparer.compare(actual, () => { return spoofOutput; });
56
- expect(comparison).to.be.true;
57
- });
58
- })
59
-
60
- describe("Indirect tests: Result of calling spoofed method is compared.", () => {
61
- it("Should set class method to return a known value when given args which define that.", /* good */ () => {
62
- let target = new SpoofClassMethodsFixture();
63
- let definition = { of: "spoofNumber", as: 17 };
64
- let arg = { on: Spoofable, plus: [ definition ] };
65
-
66
- target.spoof(arg);
67
-
68
- let spoofed = Spoofable.prototype.spoofNumber;
69
- let actual = spoofed();
70
-
71
- target.unspoof();
72
-
73
- let comparison = comparer.compare(actual, 17);
74
- expect(comparison).to.be.true;
75
- });
76
-
77
- it("Should set class method to return a known string when given args which define that.", /* good */ () => {
78
- let target = new SpoofClassMethodsFixture();
79
- let definition = { of: "spoofText", as: "return-text" };
80
- let arg = { on: Spoofable, plus: [ definition ] };
81
-
82
- target.spoof(arg);
83
-
84
- let spoofed = Spoofable.prototype.spoofText;
85
- let actual = spoofed();
86
-
87
- target.unspoof();
88
-
89
- let comparison = comparer.compare(actual, "return-text");
90
- expect(comparison).to.be.true;
91
- });
92
-
93
- it("Should set class method to return a known object when given args which define that.", /* good */ () => {
94
- let target = new SpoofClassMethodsFixture();
95
- let definition = { of: "spoofText", as: { first: "one", second: "two" } };
96
- let arg = { on: Spoofable, plus: [ definition ] };
97
-
98
- target.spoof(arg);
99
-
100
- let spoofed = Spoofable.prototype.spoofText;
101
- let actual = spoofed();
102
-
103
- target.unspoof();
104
-
105
- let comparison = comparer.compare(actual, { first: "one", second: "two" });
106
- expect(comparison).to.be.true;
107
- });
108
-
109
- it("Should set class method to return a deep spoofed object when given args which define that.", /* good */ () => {
110
- let target = new SpoofClassMethodsFixture();
111
- let definition = { of: "spoofNumber", as: [ { of: "these.those.the.other", as: 76 } ] };
112
- let arg = { on: Spoofable, plus: [ definition ] };
113
-
114
- target.spoof(arg);
115
-
116
- let spoofed = Spoofable.prototype.spoofNumber;
117
- let actual = spoofed();
118
-
119
- target.unspoof();
120
-
121
- let expected = { these: { those: { the: { other: () => { return spoofOutput; } } } } };
122
-
123
- let comparison = comparer.compare(actual, expected);
124
- expect(comparison).to.be.true;
125
-
126
- });
127
- });
128
- });
129
- });
130
-
@@ -1,95 +0,0 @@
1
- /**/
2
-
3
- import { SpoofObjectMethodsFixture } from "../../system/SpoofObjectMethodsFixture.js";
4
- import { TotalComparer } from "../../system/TotalComparer.js";
5
-
6
- import { expect } from "chai";
7
-
8
- describe("SpoofObjectMethodsFixture", () => {
9
- let comparer = new TotalComparer();
10
-
11
- describe("Direct tests: Definition of spoofed method is compared.", () => {
12
- it("Should set an empty method property when given args which define that.", /* good */ () => {
13
- let target = new SpoofObjectMethodsFixture();
14
- let definition = { of: "spoofNumber" };
15
- let arg = { with: [ definition ], in: [ ] };
16
-
17
- target.spoof(arg);
18
-
19
- let actual = arg.with[0];
20
-
21
- let comparison = comparer.compare(actual, { spoofNumber: () => { } });
22
- expect(comparison).to.be.true;
23
- });
24
-
25
- it("Should set a method to a known nonce function when given that nonce as an arg.", /* good */ () => {
26
- let target = new SpoofObjectMethodsFixture();
27
- let definition = { of: "spoofNumber", as: (a, b) => { return b - a; } };
28
- let arg = { with: [ definition ], in: [ ] };
29
-
30
- target.spoof(arg);
31
-
32
- let actual = arg.with[0];
33
-
34
- let comparison = comparer.compare(actual, { spoofNumber: (a, b) => { return b - a; } });
35
- expect(comparison).to.be.true;
36
- });
37
-
38
- it("Should set class method to a simple function returning a named parameter when given args which define that.", /* good */ () => {
39
- let target = new SpoofObjectMethodsFixture();
40
- let definition = { of: "spoofNumber" , as: 32 };
41
- let arg = { with: [ definition ], in: [ ] };
42
-
43
- target.spoof(arg);
44
-
45
- let actual = arg.with[0];
46
-
47
- let comparison = comparer.compare(actual, { spoofNumber: () => { return spoofOutput; } });
48
- expect(comparison).to.be.true;
49
- });
50
- })
51
-
52
- describe("Indirect tests: Result of calling spoofed method is compared.", () => {
53
- it("Should set a method to return a known value when given args which define that.", /* good */ () => {
54
- let target = new SpoofObjectMethodsFixture();
55
- let definition = { of: "spoofNumber", as: 17 };
56
- let arg = { with: [ definition ], in: [] };
57
-
58
- target.spoof(arg);
59
-
60
- let spoofed = arg.with[0];
61
- let actual = spoofed.spoofNumber();
62
-
63
- let comparison = comparer.compare(actual, 17);
64
- expect(comparison).to.be.true;
65
- });
66
-
67
- it("Should set a method to return a known string when given args which define that.", /* good */ () => {
68
- let target = new SpoofObjectMethodsFixture();
69
- let definition = { of: "spoofText", as: "return-text" };
70
- let arg = { with: [ definition ], in: [] };
71
-
72
- target.spoof(arg);
73
-
74
- let spoofed = arg.with[0];
75
- let actual = spoofed.spoofText();
76
-
77
- let comparison = comparer.compare(actual, "return-text");
78
- expect(comparison).to.be.true;
79
- });
80
-
81
- it("Should set a method to return a known object when given args which define that.", /* good */ () => {
82
- let target = new SpoofObjectMethodsFixture();
83
- let definition = { of: "spoofText", as: { first: "one", second: "two" } };
84
- let arg = { with: [ definition ], in: [] };
85
-
86
- target.spoof(arg);
87
-
88
- let spoofed = arg.with[0];
89
- let actual = spoofed.spoofText();
90
-
91
- let comparison = comparer.compare(actual, { first: "one", second: "two" });
92
- expect(comparison).to.be.true;
93
- });
94
- });
95
- });