test.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. 'use strict';
  2. require('../lib/chalk').set();
  3. require('../lib/worker/options').set({color: false});
  4. const path = require('path');
  5. const React = require('react');
  6. const test = require('tap').test;
  7. const delay = require('delay');
  8. const snapshotManager = require('../lib/snapshot-manager');
  9. const Test = require('../lib/test');
  10. const HelloMessage = require('./fixture/hello-message');
  11. const failingTestHint = 'Test was expected to fail, but succeeded, you should stop marking the test as failing';
  12. class ContextRef {
  13. constructor() {
  14. this.value = {};
  15. }
  16. get() {
  17. return this.value;
  18. }
  19. set(newValue) {
  20. this.value = newValue;
  21. }
  22. }
  23. function ava(fn, contextRef) {
  24. return new Test({
  25. contextRef: contextRef || new ContextRef(),
  26. failWithoutAssertions: true,
  27. fn,
  28. metadata: {type: 'test', callback: false},
  29. title: 'test'
  30. });
  31. }
  32. ava.failing = (fn, contextRef) => {
  33. return new Test({
  34. contextRef: contextRef || new ContextRef(),
  35. failWithoutAssertions: true,
  36. fn,
  37. metadata: {type: 'test', callback: false, failing: true},
  38. title: 'test.failing'
  39. });
  40. };
  41. ava.cb = (fn, contextRef) => {
  42. return new Test({
  43. contextRef: contextRef || new ContextRef(),
  44. failWithoutAssertions: true,
  45. fn,
  46. metadata: {type: 'test', callback: true},
  47. title: 'test.cb'
  48. });
  49. };
  50. ava.cb.failing = (fn, contextRef) => {
  51. return new Test({
  52. contextRef: contextRef || new ContextRef(),
  53. failWithoutAssertions: true,
  54. fn,
  55. metadata: {type: 'test', callback: true, failing: true},
  56. title: 'test.cb.failing'
  57. });
  58. };
  59. test('run test', t => {
  60. return ava(a => {
  61. a.fail();
  62. }).run().then(result => {
  63. t.is(result.passed, false);
  64. });
  65. });
  66. test('multiple asserts', t => {
  67. const instance = ava(a => {
  68. a.pass();
  69. a.pass();
  70. a.pass();
  71. });
  72. return instance.run().then(result => {
  73. t.is(result.passed, true);
  74. t.is(instance.assertCount, 3);
  75. });
  76. });
  77. test('plan assertions', t => {
  78. const instance = ava(a => {
  79. a.plan(2);
  80. a.pass();
  81. a.pass();
  82. });
  83. return instance.run().then(result => {
  84. t.is(result.passed, true);
  85. t.is(instance.planCount, 2);
  86. t.is(instance.assertCount, 2);
  87. });
  88. });
  89. test('plan assertion can be skipped', t => {
  90. const instance = ava(a => {
  91. a.plan.skip(2);
  92. a.pass();
  93. a.pass();
  94. });
  95. return instance.run().then(result => {
  96. t.is(result.passed, true);
  97. t.is(instance.planCount, null);
  98. t.is(instance.assertCount, 2);
  99. });
  100. });
  101. test('plan assertion skip() is bound', t => {
  102. const instance = ava(a => {
  103. (a.plan.skip)(2);
  104. a.pass();
  105. a.pass();
  106. });
  107. return instance.run().then(result => {
  108. t.is(result.passed, true);
  109. t.is(instance.planCount, null);
  110. t.is(instance.assertCount, 2);
  111. });
  112. });
  113. test('run more assertions than planned', t => {
  114. return ava(a => {
  115. a.plan(2);
  116. a.pass();
  117. a.pass();
  118. a.pass();
  119. }).run().then(result => {
  120. t.is(result.passed, false);
  121. t.ok(result.error);
  122. t.match(result.error.message, /Planned for 2 assertions, but got 3\./);
  123. t.is(result.error.name, 'AssertionError');
  124. });
  125. });
  126. test('fails if no assertions are run', t => {
  127. return ava(() => {}).run().then(result => {
  128. t.is(result.passed, false);
  129. t.ok(result.error);
  130. t.is(result.error.name, 'Error');
  131. t.match(result.error.message, /Test finished without running any assertions/);
  132. });
  133. });
  134. test('fails if no assertions are run, unless so planned', t => {
  135. return ava(a => a.plan(0)).run().then(result => {
  136. t.is(result.passed, true);
  137. });
  138. });
  139. test('fails if no assertions are run, unless an ended callback test', t => {
  140. return ava.cb(a => a.end()).run().then(result => {
  141. t.is(result.passed, true);
  142. });
  143. });
  144. test('wrap non-assertion errors', t => {
  145. const err = new Error();
  146. return ava(() => {
  147. throw err;
  148. }).run().then(result => {
  149. t.is(result.passed, false);
  150. t.is(result.error.message, 'Error thrown in test');
  151. t.is(result.error.name, 'AssertionError');
  152. t.is(result.error.values.length, 1);
  153. t.is(result.error.values[0].label, 'Error thrown in test:');
  154. t.match(result.error.values[0].formatted, /Error/);
  155. });
  156. });
  157. test('end can be used as callback without maintaining thisArg', t => {
  158. return ava.cb(a => {
  159. a.pass();
  160. setTimeout(a.end);
  161. }).run().then(result => {
  162. t.is(result.passed, true);
  163. });
  164. });
  165. test('end can be used as callback with error', t => {
  166. const err = new Error('failed');
  167. return ava.cb(a => {
  168. a.end(err);
  169. }).run().then(result => {
  170. t.is(result.passed, false);
  171. t.is(result.error.message, 'Callback called with an error');
  172. t.is(result.error.name, 'AssertionError');
  173. t.is(result.error.values.length, 1);
  174. t.is(result.error.values[0].label, 'Callback called with an error:');
  175. t.match(result.error.values[0].formatted, /.*Error.*\n.*message: 'failed'/);
  176. });
  177. });
  178. test('end can be used as callback with a non-error as its error argument', t => {
  179. const nonError = {foo: 'bar'};
  180. return ava.cb(a => {
  181. a.end(nonError);
  182. }).run().then(result => {
  183. t.is(result.passed, false);
  184. t.ok(result.error);
  185. t.is(result.error.message, 'Callback called with an error');
  186. t.is(result.error.name, 'AssertionError');
  187. t.is(result.error.values.length, 1);
  188. t.is(result.error.values[0].label, 'Callback called with an error:');
  189. t.match(result.error.values[0].formatted, /.*\{.*\n.*foo: 'bar'/);
  190. });
  191. });
  192. test('title returns the test title', t => {
  193. t.plan(1);
  194. return new Test({
  195. fn(a) {
  196. t.is(a.title, 'foo');
  197. a.pass();
  198. },
  199. metadata: {type: 'test', callback: false},
  200. title: 'foo'
  201. }).run();
  202. });
  203. test('handle non-assertion errors even when planned', t => {
  204. const err = new Error('bar');
  205. return ava(a => {
  206. a.plan(1);
  207. throw err;
  208. }).run().then(result => {
  209. t.is(result.passed, false);
  210. t.is(result.error.name, 'AssertionError');
  211. t.is(result.error.message, 'Error thrown in test');
  212. });
  213. });
  214. test('handle testing of arrays', t => {
  215. const instance = ava(a => {
  216. a.deepEqual(['foo', 'bar'], ['foo', 'bar']);
  217. });
  218. return instance.run().then(result => {
  219. t.is(result.passed, true);
  220. t.is(instance.assertCount, 1);
  221. });
  222. });
  223. test('handle falsy testing of arrays', t => {
  224. const instance = ava(a => {
  225. a.notDeepEqual(['foo', 'bar'], ['foo', 'bar', 'cat']);
  226. });
  227. return instance.run().then(result => {
  228. t.is(result.passed, true);
  229. t.is(instance.assertCount, 1);
  230. });
  231. });
  232. test('handle testing of objects', t => {
  233. const instance = ava(a => {
  234. a.deepEqual({
  235. foo: 'foo',
  236. bar: 'bar'
  237. }, {
  238. foo: 'foo',
  239. bar: 'bar'
  240. });
  241. });
  242. return instance.run().then(result => {
  243. t.is(result.passed, true);
  244. t.is(instance.assertCount, 1);
  245. });
  246. });
  247. test('handle falsy testing of objects', t => {
  248. const instance = ava(a => {
  249. a.notDeepEqual({
  250. foo: 'foo',
  251. bar: 'bar'
  252. }, {
  253. foo: 'foo',
  254. bar: 'bar',
  255. cat: 'cake'
  256. });
  257. });
  258. return instance.run().then(result => {
  259. t.is(result.passed, true);
  260. t.is(instance.assertCount, 1);
  261. });
  262. });
  263. test('planned async assertion', t => {
  264. const instance = ava.cb(a => {
  265. a.plan(1);
  266. setTimeout(() => {
  267. a.pass();
  268. a.end();
  269. }, 100);
  270. });
  271. return instance.run().then(result => {
  272. t.is(result.passed, true);
  273. t.is(instance.assertCount, 1);
  274. });
  275. });
  276. test('async assertion with `.end()`', t => {
  277. const instance = ava.cb(a => {
  278. setTimeout(() => {
  279. a.pass();
  280. a.end();
  281. }, 100);
  282. });
  283. return instance.run().then(result => {
  284. t.is(result.passed, true);
  285. t.is(instance.assertCount, 1);
  286. });
  287. });
  288. test('more assertions than planned should emit an assertion error', t => {
  289. return ava(a => {
  290. a.plan(1);
  291. a.pass();
  292. a.pass();
  293. }).run().then(result => {
  294. t.is(result.passed, false);
  295. t.is(result.error.name, 'AssertionError');
  296. });
  297. });
  298. test('record test duration', t => {
  299. return ava.cb(a => {
  300. a.plan(1);
  301. setTimeout(() => {
  302. a.true(true);
  303. a.end();
  304. }, 1234);
  305. }).run().then(result => {
  306. t.is(result.passed, true);
  307. t.true(result.duration >= 1000);
  308. });
  309. });
  310. test('wait for test to end', t => {
  311. const instance = ava.cb(a => {
  312. a.plan(1);
  313. setTimeout(() => {
  314. a.pass();
  315. a.end();
  316. }, 1234);
  317. });
  318. return instance.run().then(result => {
  319. t.is(result.passed, true);
  320. t.is(instance.planCount, 1);
  321. t.is(instance.assertCount, 1);
  322. t.true(result.duration >= 1000);
  323. });
  324. });
  325. test('fails with the first assertError', t => {
  326. return ava(a => {
  327. a.plan(2);
  328. a.is(1, 2);
  329. a.is(3, 4);
  330. }).run().then(result => {
  331. t.is(result.passed, false);
  332. t.is(result.error.name, 'AssertionError');
  333. t.is(result.error.values.length, 1);
  334. t.is(result.error.values[0].label, 'Difference:');
  335. t.match(result.error.values[0].formatted, /- 1\n\+ 2/);
  336. });
  337. });
  338. test('failing pending assertion causes test to fail, not promise rejection', t => {
  339. return ava(a => {
  340. return a.throws(Promise.resolve()).then(() => {
  341. throw new Error('Should be ignored');
  342. });
  343. }).run().then(result => {
  344. t.is(result.passed, false);
  345. t.notMatch(result.error.message, /Rejected promise returned by test/);
  346. });
  347. });
  348. test('fails with thrown falsy value', t => {
  349. return ava(() => {
  350. throw 0; // eslint-disable-line no-throw-literal
  351. }).run().then(result => {
  352. t.is(result.passed, false);
  353. t.is(result.error.message, 'Error thrown in test');
  354. t.is(result.error.name, 'AssertionError');
  355. t.is(result.error.values.length, 1);
  356. t.is(result.error.values[0].label, 'Error thrown in test:');
  357. t.match(result.error.values[0].formatted, /0/);
  358. });
  359. });
  360. test('fails with thrown non-error object', t => {
  361. const obj = {foo: 'bar'};
  362. return ava(() => {
  363. throw obj;
  364. }).run().then(result => {
  365. t.is(result.passed, false);
  366. t.is(result.error.message, 'Error thrown in test');
  367. t.is(result.error.name, 'AssertionError');
  368. t.is(result.error.values.length, 1);
  369. t.is(result.error.values[0].label, 'Error thrown in test:');
  370. t.match(result.error.values[0].formatted, /.*\{.*\n.*foo: 'bar'/);
  371. });
  372. });
  373. test('skipped assertions count towards the plan', t => {
  374. const instance = ava(a => {
  375. a.plan(15);
  376. a.pass.skip();
  377. a.fail.skip();
  378. a.is.skip(1, 1);
  379. a.not.skip(1, 2);
  380. a.deepEqual.skip({foo: 'bar'}, {foo: 'bar'});
  381. a.notDeepEqual.skip({foo: 'bar'}, {baz: 'thud'});
  382. a.throws.skip(() => {
  383. throw new Error(); // eslint-disable-line unicorn/error-message
  384. });
  385. a.notThrows.skip(() => {});
  386. a.snapshot.skip({});
  387. a.truthy.skip(true);
  388. a.falsy.skip(false);
  389. a.true.skip(true);
  390. a.false.skip(false);
  391. a.regex.skip('foo', /foo/);
  392. a.notRegex.skip('bar', /foo/);
  393. });
  394. return instance.run().then(result => {
  395. t.is(result.passed, true);
  396. t.is(instance.planCount, 15);
  397. t.is(instance.assertCount, 15);
  398. });
  399. });
  400. test('assertion.skip() is bound', t => {
  401. const instance = ava(a => {
  402. a.plan(15);
  403. (a.pass.skip)();
  404. (a.fail.skip)();
  405. (a.is.skip)(1, 1);
  406. (a.not.skip)(1, 2);
  407. (a.deepEqual.skip)({foo: 'bar'}, {foo: 'bar'});
  408. (a.notDeepEqual.skip)({foo: 'bar'}, {baz: 'thud'});
  409. (a.throws.skip)(() => {
  410. throw new Error(); // eslint-disable-line unicorn/error-message
  411. });
  412. (a.notThrows.skip)(() => {});
  413. (a.snapshot.skip)({});
  414. (a.truthy.skip)(true);
  415. (a.falsy.skip)(false);
  416. (a.true.skip)(true);
  417. (a.false.skip)(false);
  418. (a.regex.skip)('foo', /foo/);
  419. (a.notRegex.skip)('bar', /foo/);
  420. });
  421. return instance.run().then(result => {
  422. t.is(result.passed, true);
  423. t.is(instance.planCount, 15);
  424. t.is(instance.assertCount, 15);
  425. });
  426. });
  427. test('throws and notThrows work with promises', t => {
  428. let asyncCalled = false;
  429. const instance = ava(a => {
  430. a.plan(2);
  431. return Promise.all([
  432. a.throws(delay.reject(10, new Error('foo')), 'foo'),
  433. a.notThrows(delay(20).then(() => {
  434. asyncCalled = true;
  435. }))
  436. ]);
  437. });
  438. return instance.run().then(result => {
  439. t.is(result.passed, true);
  440. t.is(instance.planCount, 2);
  441. t.is(instance.assertCount, 2);
  442. t.is(asyncCalled, true);
  443. });
  444. });
  445. test('end should not be called multiple times', t => {
  446. return ava.cb(a => {
  447. a.pass();
  448. a.end();
  449. a.end();
  450. }).run().then(result => {
  451. t.is(result.passed, false);
  452. t.is(result.error.message, '`t.end()` called more than once');
  453. });
  454. });
  455. test('cb test that throws sync', t => {
  456. const err = new Error('foo');
  457. return ava.cb(() => {
  458. throw err;
  459. }).run().then(result => {
  460. t.is(result.passed, false);
  461. t.is(result.error.message, 'Error thrown in test');
  462. t.is(result.error.name, 'AssertionError');
  463. });
  464. });
  465. test('multiple resolving and rejecting promises passed to t.throws/t.notThrows', t => {
  466. const instance = ava(a => {
  467. a.plan(6);
  468. const promises = [];
  469. for (let i = 0; i < 3; i++) {
  470. promises.push(
  471. a.throws(delay.reject(10, new Error('foo')), 'foo'),
  472. a.notThrows(delay(10), 'foo')
  473. );
  474. }
  475. return Promise.all(promises);
  476. });
  477. return instance.run().then(result => {
  478. t.is(result.passed, true);
  479. t.is(instance.planCount, 6);
  480. t.is(instance.assertCount, 6);
  481. });
  482. });
  483. test('fails if test ends while there are pending assertions', t => {
  484. return ava(a => {
  485. a.throws(Promise.reject(new Error()));
  486. }).run().then(result => {
  487. t.is(result.passed, false);
  488. t.is(result.error.name, 'Error');
  489. t.match(result.error.message, /Test finished, but an assertion is still pending/);
  490. });
  491. });
  492. test('fails if callback test ends while there are pending assertions', t => {
  493. return ava.cb(a => {
  494. a.throws(Promise.reject(new Error()));
  495. a.end();
  496. }).run().then(result => {
  497. t.is(result.passed, false);
  498. t.is(result.error.name, 'Error');
  499. t.match(result.error.message, /Test finished, but an assertion is still pending/);
  500. });
  501. });
  502. test('fails if async test ends while there are pending assertions', t => {
  503. return ava(a => {
  504. a.throws(Promise.reject(new Error()));
  505. return Promise.resolve();
  506. }).run().then(result => {
  507. t.is(result.passed, false);
  508. t.is(result.error.name, 'Error');
  509. t.match(result.error.message, /Test finished, but an assertion is still pending/);
  510. });
  511. });
  512. // This behavior is incorrect, but feedback cannot be provided to the user due to
  513. // https://github.com/avajs/ava/issues/1330
  514. test('no crash when adding assertions after the test has ended', t => {
  515. t.plan(3);
  516. ava(a => {
  517. a.pass();
  518. setImmediate(() => {
  519. t.doesNotThrow(() => a.pass());
  520. });
  521. }).run();
  522. ava(a => {
  523. a.pass();
  524. setImmediate(() => {
  525. t.doesNotThrow(() => a.fail());
  526. });
  527. }).run();
  528. ava(a => {
  529. a.pass();
  530. setImmediate(() => {
  531. t.doesNotThrow(() => a.notThrows(Promise.resolve()));
  532. });
  533. }).run();
  534. });
  535. test('contextRef', t => {
  536. new Test({
  537. contextRef: {
  538. get() {
  539. return {foo: 'bar'};
  540. }
  541. },
  542. failWithoutAssertions: true,
  543. fn(a) {
  544. a.pass();
  545. t.strictDeepEqual(a.context, {foo: 'bar'});
  546. t.end();
  547. },
  548. metadata: {type: 'test'},
  549. onResult() {},
  550. title: 'foo'
  551. }).run();
  552. });
  553. test('failing tests should fail', t => {
  554. return ava.failing('foo', a => {
  555. a.fail();
  556. }).run().then(result => {
  557. t.is(result.passed, true);
  558. });
  559. });
  560. test('failing callback tests should end without error', t => {
  561. const err = new Error('failed');
  562. return ava.cb.failing(a => {
  563. a.end(err);
  564. }).run().then(result => {
  565. t.is(result.passed, true);
  566. });
  567. });
  568. test('failing tests must not pass', t => {
  569. return ava.failing(a => {
  570. a.pass();
  571. }).run().then(result => {
  572. t.is(result.passed, false);
  573. t.is(result.error.message, failingTestHint);
  574. });
  575. });
  576. test('failing callback tests must not pass', t => {
  577. return ava.cb.failing(a => {
  578. a.pass();
  579. a.end();
  580. }).run().then(result => {
  581. t.is(result.passed, false);
  582. });
  583. });
  584. test('failing tests must not return a fulfilled promise', t => {
  585. return ava.failing(a => {
  586. return Promise.resolve().then(() => a.pass());
  587. }).run().then(result => {
  588. t.is(result.passed, false);
  589. t.is(result.error.message, failingTestHint);
  590. });
  591. });
  592. test('failing tests pass when returning a rejected promise', t => {
  593. return ava.failing(a => {
  594. a.plan(1);
  595. return a.notThrows(delay(10), 'foo').then(() => Promise.reject());
  596. }).run().then(result => {
  597. t.is(result.passed, true);
  598. });
  599. });
  600. test('failing tests pass with `t.throws(nonThrowingPromise)`', t => {
  601. return ava.failing(a => {
  602. return a.throws(Promise.resolve(10));
  603. }).run().then(result => {
  604. t.is(result.passed, true);
  605. });
  606. });
  607. test('failing tests fail with `t.notThrows(throws)`', t => {
  608. return ava.failing(a => {
  609. return a.notThrows(Promise.resolve('foo'));
  610. }).run().then(result => {
  611. t.is(result.passed, false);
  612. t.is(result.error.message, failingTestHint);
  613. });
  614. });
  615. test('log from tests', t => {
  616. return ava(a => {
  617. a.log('a log message from a test');
  618. t.true(true);
  619. a.log('another log message from a test');
  620. a.log({b: 1, c: {d: 2}}, 'complex log', 5, 5.1);
  621. a.log();
  622. (a.log)('bound');
  623. }).run().then(result => {
  624. t.deepEqual(
  625. result.logs,
  626. [
  627. 'a log message from a test',
  628. 'another log message from a test',
  629. '{\n b: 1,\n c: {\n d: 2,\n },\n} complex log 5 5.1',
  630. 'bound'
  631. ]
  632. );
  633. });
  634. });
  635. test('assertions are bound', t => {
  636. // This does not test .fail() and .snapshot(). It'll suffice.
  637. return ava(a => {
  638. (a.plan)(13);
  639. (a.pass)();
  640. (a.is)(1, 1);
  641. (a.not)(1, 2);
  642. (a.deepEqual)({foo: 'bar'}, {foo: 'bar'});
  643. (a.notDeepEqual)({foo: 'bar'}, {baz: 'thud'});
  644. (a.throws)(() => {
  645. throw new Error(); // eslint-disable-line unicorn/error-message
  646. });
  647. (a.notThrows)(() => {});
  648. (a.truthy)(true);
  649. (a.falsy)(false);
  650. (a.true)(true);
  651. (a.false)(false);
  652. (a.regex)('foo', /foo/);
  653. (a.notRegex)('bar', /foo/);
  654. }).run().then(result => {
  655. t.true(result.passed);
  656. });
  657. });
  658. // Snapshots reused from test/assert.js
  659. test('snapshot assertion can be skipped', t => {
  660. const projectDir = path.join(__dirname, 'fixture');
  661. const manager = snapshotManager.load({
  662. file: __filename,
  663. name: 'assert.js',
  664. projectDir,
  665. relFile: 'test/assert.js',
  666. fixedLocation: null,
  667. testDir: projectDir,
  668. updating: false
  669. });
  670. return new Test({
  671. compareTestSnapshot: options => manager.compare(options),
  672. updateSnapshots: false,
  673. metadata: {},
  674. title: 'passes',
  675. fn(t) {
  676. t.snapshot.skip({not: {a: 'match'}});
  677. t.snapshot(React.createElement(HelloMessage, {name: 'Sindre'}));
  678. }
  679. }).run().then(result => {
  680. t.true(result.passed);
  681. });
  682. });
  683. test('snapshot assertion cannot be skipped when updating snapshots', t => {
  684. return new Test({
  685. updateSnapshots: true,
  686. metadata: {},
  687. title: 'passes',
  688. fn(t) {
  689. t.snapshot.skip({not: {a: 'match'}});
  690. }
  691. }).run().then(result => {
  692. t.false(result.passed);
  693. t.is(result.error.message, 'Snapshot assertions cannot be skipped when updating snapshots');
  694. });
  695. });
  696. test('implementation runs with null scope', t => {
  697. return ava(function (a) {
  698. a.pass();
  699. t.is(this, null);
  700. }).run();
  701. });