You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: readme.md
+52-54
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ $ ava --init
74
74
75
75
If you prefer using npm:
76
76
77
-
```
77
+
```console
78
78
$ npm install --global ava
79
79
$ ava --init
80
80
```
@@ -109,8 +109,7 @@ Alternatively using npm:
109
109
$ npm install --save-dev ava
110
110
```
111
111
112
-
You'll have to configure the `test` script in your `package.json` to use `ava`
113
-
(see above).
112
+
You'll have to configure the `test` script in your `package.json` to use `ava` (see above).
114
113
115
114
### Create your test file
116
115
@@ -156,7 +155,7 @@ $ ava --help
156
155
--init Add AVA to your project
157
156
--fail-fast Stop after first test failure
158
157
--serial, -s Run tests serially
159
-
--tap, -- [ ] Generate TAP output
158
+
--tap, -t Generate TAP output
160
159
--verbose, -v Enable verbose output
161
160
--no-cache Disable the transpiler cache
162
161
--no-power-assert Disable Power Assert
@@ -165,7 +164,7 @@ $ ava --help
165
164
--source, -S Pattern to match source files so tests can be re-run (Can be repeated)
166
165
--timeout, -T Set global timeout
167
166
--concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)
168
-
--update-snapshots, -u Update all snapshots
167
+
--update-snapshots, -u Update snapshots
169
168
170
169
Examples
171
170
ava
@@ -274,7 +273,7 @@ Tests are run concurrently. You can specify synchronous and asynchronous tests.
274
273
275
274
We *highly* recommend the use of [async functions](#async-function-support). They make asynchronous code concise and readable, and they implicitly return a promise so you don't have to.
276
275
277
-
If you're unable to use promises or observables, you may enable "callback mode" by defining your test with `test.cb([title], fn)`. Tests declared this way **must** be manually ended with `t.end()`. This mode is mainly intended for testing callback-style APIs.
276
+
If you're unable to use promises or observables, you may enable "callback mode" by defining your test with `test.cb([title], fn)`. Tests declared this way **must** be manually ended with `t.end()`. This mode is mainly intended for testing callback-style APIs. However, we would strongly recommend [promisifying](https://github.com/sindresorhus/pify) callback-style APIs instead of using "callback mode", as this results in more correct and readable tests.
278
277
279
278
You must define all tests synchronously. They can't be defined inside `setTimeout`, `setImmediate`, etc.
280
279
@@ -350,22 +349,22 @@ test(t => {
350
349
for (let i =0; i <3; i++) {
351
350
t.true(i <3);
352
351
}
353
-
}); //fails, 3 assertions are executed which is too many
352
+
}); //Fails, 3 assertions are executed which is too many
354
353
355
354
test(t=> {
356
355
t.plan(1);
357
356
358
357
someAsyncFunction(() => {
359
358
t.pass();
360
359
});
361
-
}); //fails, the test ends synchronously before the assertion is executed
360
+
}); //Fails, the test ends synchronously before the assertion is executed
362
361
```
363
362
364
363
### Running tests serially
365
364
366
365
By default tests are run concurrently, which is awesome. Sometimes though you have to write tests that cannot run concurrently.
367
366
368
-
In these rare cases you can use the `.serial` modifier. It'll force those tests to run serially *before* the concurrent ones.
367
+
In these rare cases you can use the `.serial` modifier. It will force those tests to run serially *before* the concurrent ones.
369
368
370
369
```js
371
370
test.serial(t=> {
@@ -454,12 +453,12 @@ test.only('boo will run but not exclusively', t => {
454
453
t.pass();
455
454
});
456
455
457
-
//won't run, no title
456
+
//Won't run, no title
458
457
test(function (t) {
459
458
t.fail();
460
459
});
461
460
462
-
//won't run, no explicit title
461
+
//Won't run, no explicit title
463
462
test(functionfoo(t) {
464
463
t.fail();
465
464
});
@@ -494,7 +493,7 @@ This allows you to merge `.failing` tests before a fix is implemented without br
@@ -514,35 +513,35 @@ Like `test()` these methods take an optional title and a callback function. The
514
513
515
514
```js
516
515
test.before(t=> {
517
-
//this runs before all tests
516
+
//This runs before all tests
518
517
});
519
518
520
519
test.before(t=> {
521
-
//this runs after the above, but before tests
520
+
//This runs after the above, but before tests
522
521
});
523
522
524
523
test.after('cleanup', t=> {
525
-
//this runs after all tests
524
+
//This runs after all tests
526
525
});
527
526
528
527
test.after.always('guaranteed cleanup', t=> {
529
-
//this will always run, regardless of earlier failures
528
+
//This will always run, regardless of earlier failures
530
529
});
531
530
532
531
test.beforeEach(t=> {
533
-
//this runs before each test
532
+
//This runs before each test
534
533
});
535
534
536
535
test.afterEach(t=> {
537
-
//this runs after each test
536
+
//This runs after each test
538
537
});
539
538
540
539
test.afterEach.always(t=> {
541
-
//this runs after each test and other test hooks, even if they failed
540
+
//This runs after each test and other test hooks, even if they failed
542
541
});
543
542
544
543
test(t=> {
545
-
//regular test
544
+
//Regular test
546
545
});
547
546
```
548
547
@@ -690,32 +689,32 @@ You can customize how AVA transpiles the test files through the `babel` option i
690
689
691
690
```json
692
691
{
693
-
"ava": {
694
-
"babel": {
695
-
"presets": [
696
-
"es2015",
697
-
"stage-0",
698
-
"react"
699
-
]
700
-
}
701
-
},
692
+
"ava": {
693
+
"babel": {
694
+
"presets": [
695
+
"es2015",
696
+
"stage-0",
697
+
"react"
698
+
]
699
+
}
700
+
}
702
701
}
703
702
```
704
703
705
704
You can also use the special `"inherit"` keyword. This makes AVA defer to the Babel config in your [`.babelrc` or `package.json` file](https://babeljs.io/docs/usage/babelrc/). This way your test files will be transpiled using the same config as your source files without having to repeat it just for AVA:
706
705
707
706
```json
708
707
{
709
-
"babel": {
710
-
"presets": [
711
-
"es2015",
712
-
"stage-0",
713
-
"react"
714
-
]
715
-
},
716
-
"ava": {
717
-
"babel": "inherit"
718
-
},
708
+
"babel": {
709
+
"presets": [
710
+
"es2015",
711
+
"stage-0",
712
+
"react"
713
+
]
714
+
},
715
+
"ava": {
716
+
"babel": "inherit"
717
+
}
719
718
}
720
719
```
721
720
@@ -770,7 +769,7 @@ test(async function (t) {
770
769
t.true(value);
771
770
});
772
771
773
-
//async arrow function
772
+
//Async arrow function
774
773
test(asynct=> {
775
774
constvalue=awaitpromiseFn();
776
775
t.true(value);
@@ -788,7 +787,7 @@ test(t => {
788
787
t.plan(3);
789
788
returnObservable.of(1, 2, 3, 4, 5, 6)
790
789
.filter(n=> {
791
-
//only even numbers
790
+
//Only even numbers
792
791
return n %2===0;
793
792
})
794
793
.map(() =>t.pass());
@@ -801,7 +800,7 @@ AVA supports using `t.end` as the final callback when using node-style error-fir
801
800
802
801
```js
803
802
test.cb(t=> {
804
-
// t.end automatically checks for error as first argument
803
+
//`t.end` automatically checks for error as first argument
805
804
fs.readFile('data.txt', t.end);
806
805
});
807
806
```
@@ -814,7 +813,7 @@ AVA resets a timer after each test, forcing tests to quit if no new test results
814
813
815
814
You can set timeouts in a human-readable way:
816
815
817
-
```
816
+
```console
818
817
$ ava --timeout=10s # 10 seconds
819
818
$ ava --timeout=2m # 2 minutes
820
819
$ ava --timeout=100 # 100 milliseconds
@@ -866,7 +865,7 @@ Assertions are mixed into the [execution object](#t) provided to each test imple
866
865
867
866
```js
868
867
test(t=> {
869
-
t.truthy('unicorn'); //assertion
868
+
t.truthy('unicorn'); //Assertion
870
869
});
871
870
```
872
871
@@ -972,14 +971,14 @@ Snapshot testing comes as another kind of assertion and uses [jest-snapshot](htt
972
971
When used with React, it looks very similar to Jest:
973
972
974
973
```js
975
-
//your component
974
+
//Your component
976
975
constHelloWorld= () =><h1>Hello World...!</h1>;
977
976
978
977
exportdefaultHelloWorld;
979
978
```
980
979
981
980
```js
982
-
//your test
981
+
//Your test
983
982
importtestfrom'ava';
984
983
importrenderfrom'react-test-renderer';
985
984
@@ -1007,7 +1006,9 @@ Every time you run this test afterwards, it will check if the component render h
1007
1006
1008
1007
That might look like this:
1009
1008
1010
-
`$ ava --update-snapshots`
1009
+
```console
1010
+
$ ava --update-snapshots
1011
+
```
1011
1012
1012
1013
Note that snapshots can be used for much more than just testing components - you can equally well test any other (data) structure that you can stringify.
1013
1014
@@ -1018,7 +1019,7 @@ Any assertion can be skipped using the `skip` modifier. Skipped assertions are s
1018
1019
```js
1019
1020
test(t=> {
1020
1021
t.plan(2);
1021
-
t.skip.is(foo(), 5); //no need to change your plan count when skipping
1022
+
t.skip.is(foo(), 5); //No need to change your plan count when skipping
1022
1023
t.is(1, 1);
1023
1024
});
1024
1025
```
@@ -1128,23 +1129,20 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
1128
1129
1129
1130
## Related
1130
1131
1132
+
-[eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava) - Lint rules for AVA tests
1131
1133
-[sublime-ava](https://github.com/avajs/sublime-ava) - Snippets for AVA tests
1132
1134
-[atom-ava](https://github.com/avajs/atom-ava) - Snippets for AVA tests
1133
1135
-[vscode-ava](https://github.com/samverschueren/vscode-ava) - Snippets for AVA tests
1134
-
-[eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava) - Lint rules for AVA tests
1135
1136
-[gulp-ava](https://github.com/avajs/gulp-ava) - Run tests with gulp
1136
1137
-[grunt-ava](https://github.com/avajs/grunt-ava) - Run tests with grunt
1137
-
-[fly-ava](https://github.com/pine/fly-ava) - Run tests with fly
1138
-
-[start-ava](https://github.com/start-runner/ava) - Run tests with start
0 commit comments