a_mock 2.0.3 → 2.0.4
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/README.md +0 -165
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/partialMock/expectAnything.js +4 -3
- package/partialMock/expectCore.js +8 -7
- package/partialMock/expectEmpty.js +5 -4
package/README.md
CHANGED
|
@@ -13,15 +13,6 @@ npm install a_mock
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
__If you want the test framework, install it globally too:__
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
npm install a_mock -g
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
16
|
_Mocking_
|
|
26
17
|
===================
|
|
27
18
|
|
|
@@ -456,160 +447,4 @@ function success(arg) {
|
|
|
456
447
|
function error(e) {
|
|
457
448
|
console.log(e.stack);//will happen
|
|
458
449
|
}
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
_A test framework_
|
|
462
|
-
===================
|
|
463
|
-
<b>From version 3.0.0 this is in a separate package: [npmjs.com/package/a_test](https://npmjs.com/package/a_test)</b>
|
|
464
|
-
_A_ test framework is a simplistic, magic-free library providing unit-testing facilities with a compact, bdd-style syntax.
|
|
465
|
-
|
|
466
|
-
In contrast to other bdd-style test frameworks, it doesn't allow nesting suites in each other in order to test the SUT(subject under test) in different states. Instead, the framework relies on folder structure to describe the state. The SUT currently has that folder structure. Suite names are generated based on their filenames. As a result, there will be many small test files without nested test suites instead of a few big test files with nested test suites.
|
|
467
|
-
|
|
468
|
-
Test setup, the "Arrange-Act" part of suites, is separated from the "Assert" part. This way the same setup can be used across different suites. Test setups can be chained.
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
Examples below can be found here: https://github.com/alfateam/a_demo
|
|
472
|
-
|
|
473
|
-
Example
|
|
474
|
-
---------
|
|
475
|
-
The test runner ( _a_ ) will search for all files named 'when*.js' in the current and sub-directories.
|
|
476
|
-
|
|
477
|
-
Given the following file structure
|
|
478
|
-
|
|
479
|
-
- demo/
|
|
480
|
-
- counter.js
|
|
481
|
-
- counter_specs/
|
|
482
|
-
- new/
|
|
483
|
-
- increment.js
|
|
484
|
-
- when_incremented.js
|
|
485
|
-
- new.js
|
|
486
|
-
- when_new.js
|
|
487
|
-
|
|
488
|
-
__counter.js__
|
|
489
|
-
|
|
490
|
-
```js
|
|
491
|
-
module.exports = function () {
|
|
492
|
-
var counter = {
|
|
493
|
-
value: 0,
|
|
494
|
-
increment: function() { value++; }
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
return counter;
|
|
498
|
-
}
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
__counter_specs/new.js__
|
|
502
|
-
|
|
503
|
-
```js
|
|
504
|
-
function act(c) {
|
|
505
|
-
var createCounter = require('../counter');
|
|
506
|
-
c.sut = createCounter();
|
|
507
|
-
}
|
|
508
|
-
module.exports = act;
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
__counter_specs/when_new.js__
|
|
512
|
-
|
|
513
|
-
```js
|
|
514
|
-
var c = {}; //test context object
|
|
515
|
-
var when = require('a_mock').when;
|
|
516
|
-
|
|
517
|
-
when('./new', c). //set up
|
|
518
|
-
it('should be an object').
|
|
519
|
-
assertEqual('object', typeof c.sut)
|
|
520
|
-
it('should have value equal to zero').
|
|
521
|
-
assertEqual(0, c.sut.value).
|
|
522
|
-
it('should fail just for fun').
|
|
523
|
-
assertFail('error message');
|
|
524
|
-
|
|
525
|
-
```
|
|
526
|
-
|
|
527
|
-
__counter_specs/new/increment.js__
|
|
528
|
-
|
|
529
|
-
```js
|
|
530
|
-
function act(c) {
|
|
531
|
-
c.sut.increment();
|
|
532
|
-
}
|
|
533
|
-
act.base = '../new';
|
|
534
|
-
module.exports = act;
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
__counter_specs/new/when_incremented.js__
|
|
538
|
-
|
|
539
|
-
```js
|
|
540
|
-
var c = {};
|
|
541
|
-
var when = require('a_mock').when;
|
|
542
|
-
|
|
543
|
-
when('./increment', c).
|
|
544
|
-
it('should have value equal to 1').
|
|
545
|
-
assertEqual(1, c.sut.value);
|
|
546
|
-
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
__In demo directory, run _a_ __
|
|
550
|
-
|
|
551
|
-
user@localhost:~/a_demo $ a
|
|
552
|
-
|
|
553
|
-
» counter_specs » new
|
|
554
|
-
|
|
555
|
-
✓ should be an object
|
|
556
|
-
✓ should have value equal to zero
|
|
557
|
-
✘ should fail just for fun
|
|
558
|
-
|
|
559
|
-
» counter_specs » new » increment
|
|
560
|
-
|
|
561
|
-
✓ should have value equal to 1
|
|
562
|
-
|
|
563
|
-
========== Summary =============
|
|
564
|
-
|
|
565
|
-
counter_specs » new
|
|
566
|
-
✘ should fail just for fun
|
|
567
|
-
|
|
568
|
-
AssertionError: error message
|
|
569
|
-
at retval.assertFail (/home/user/a_demo/node_modules/a/when/it.js:14:11)
|
|
570
|
-
at Object.test (/home/user/a_demo/node_modules/a/when/test_invoker.js:5:3)
|
|
571
|
-
at Object.retval.assertFail (/home/user/a_demo/node_modules/a/when/it.js:13:5)
|
|
572
|
-
at Object.<anonymous> (/home/user/a_demo/counter_specs/when_new.js:11:3)
|
|
573
|
-
at Module._compile (module.js:449:26)
|
|
574
|
-
at Object.Module._extensions..js (module.js:467:10)
|
|
575
|
-
at Module.load (module.js:356:32)
|
|
576
|
-
at Function.Module._load (module.js:312:12)
|
|
577
|
-
at Module.require (module.js:362:17)
|
|
578
|
-
at require (module.js:378:17)
|
|
579
|
-
------------
|
|
580
|
-
|
|
581
|
-
suites: 2, passed: 3, failed: 1
|
|
582
|
-
|
|
583
|
-
Async test support
|
|
584
|
-
------------------
|
|
585
|
-
Modified act files should look like this:
|
|
586
|
-
|
|
587
|
-
```js
|
|
588
|
-
|
|
589
|
-
function act(c) {
|
|
590
|
-
...
|
|
591
|
-
return c.sut(c.arguments); //returns promise
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
```
|
|
595
|
-
|
|
596
|
-
or
|
|
597
|
-
|
|
598
|
-
```js
|
|
599
|
-
|
|
600
|
-
async function act(c) {
|
|
601
|
-
...
|
|
602
|
-
await c.sut(c.arguments);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
```
|
|
606
|
-
Test file should look like this:
|
|
607
|
-
```js
|
|
608
|
-
var when = require('a_mock').when;
|
|
609
|
-
var c = {};
|
|
610
|
-
|
|
611
|
-
when(c).then(it => {
|
|
612
|
-
it('....').assertXXXX();
|
|
613
|
-
});
|
|
614
|
-
|
|
615
450
|
```
|
package/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ interface RepeatControl {
|
|
|
40
40
|
|
|
41
41
|
interface ExpectationTerminal<R, TArgs extends any[], TOrigArgs extends any[] = TArgs> {
|
|
42
42
|
return(value: R): RepeatControl;
|
|
43
|
-
|
|
43
|
+
returnLoose(value?: any): RepeatControl;
|
|
44
44
|
whenCalled(callback: CallbackFor<TOrigArgs>): ExpectationTerminal<R, TArgs, TOrigArgs>;
|
|
45
45
|
repeat(times: number): RepeatControl;
|
|
46
46
|
repeatAny(): RepeatControl;
|
package/package.json
CHANGED
|
@@ -26,9 +26,10 @@ function expectAnything(index,mockContext) {
|
|
|
26
26
|
|
|
27
27
|
c.ignoreAll = c.expectAnything;
|
|
28
28
|
|
|
29
|
-
c.return = function(arg) {
|
|
30
|
-
return _return(arg,index+1,mockContext);
|
|
31
|
-
};
|
|
29
|
+
c.return = function(arg) {
|
|
30
|
+
return _return(arg,index+1,mockContext);
|
|
31
|
+
};
|
|
32
|
+
c.returnLoose = c.return;
|
|
32
33
|
|
|
33
34
|
c.whenCalled = function(callback) {
|
|
34
35
|
mockContext.whenCalledEmitter.add(callback);
|
|
@@ -35,9 +35,10 @@ function expect(hasCorrectArgument,index,mockContext) {
|
|
|
35
35
|
return expectArray(index+1,mockContext,array);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
c.return = function(arg) {
|
|
39
|
-
return _return(arg,index+1,mockContext);
|
|
40
|
-
};
|
|
38
|
+
c.return = function(arg) {
|
|
39
|
+
return _return(arg,index+1,mockContext);
|
|
40
|
+
};
|
|
41
|
+
c.returnLoose = c.return;
|
|
41
42
|
|
|
42
43
|
c.whenCalled = function(callback) {
|
|
43
44
|
mockContext.whenCalledEmitter.add(callback);
|
|
@@ -57,10 +58,10 @@ function expect(hasCorrectArgument,index,mockContext) {
|
|
|
57
58
|
return _return(undefined,index+1,mockContext).repeatAny();
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
c.resolve = function(value) {
|
|
61
|
-
var promise = newThen.resolve(value);
|
|
62
|
-
return c.return(promise);
|
|
63
|
-
};
|
|
61
|
+
c.resolve = function(value) {
|
|
62
|
+
var promise = newThen.resolve(value);
|
|
63
|
+
return c.return(promise);
|
|
64
|
+
};
|
|
64
65
|
|
|
65
66
|
c.reject = function(value) {
|
|
66
67
|
var promise = newThen.reject(value);
|
|
@@ -10,9 +10,10 @@ function expectEmpty(mockContext) {
|
|
|
10
10
|
mockContext.compositeAreCorrectArguments.add(hasCorrectArgument);
|
|
11
11
|
mockContext.numberOfArgs = 0;
|
|
12
12
|
|
|
13
|
-
c.return = function(arg) {
|
|
14
|
-
return _return(arg,0,mockContext);
|
|
15
|
-
};
|
|
13
|
+
c.return = function(arg) {
|
|
14
|
+
return _return(arg,0,mockContext);
|
|
15
|
+
};
|
|
16
|
+
c.returnLoose = c.return;
|
|
16
17
|
|
|
17
18
|
c.whenCalled = function(callback) {
|
|
18
19
|
mockContext.whenCalledEmitter.add(callback);
|
|
@@ -45,4 +46,4 @@ function expectEmpty(mockContext) {
|
|
|
45
46
|
return c;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
module.exports = expectEmpty;
|
|
49
|
+
module.exports = expectEmpty;
|