Questions tagged [ava]

AVA is a fast and simple JavaScript test runner with builtin support for ES2015.

Links

Description

Even though JavaScript is single-threaded, IO in Node.js can happen in parallel due to its async nature. AVA takes advantage of this and runs your tests concurrently, which is especially beneficial for IO heavy tests. In addition, test files are run in parallel as separate processes, giving you even better performance and an isolated environment for each test file.

Highlights

  • Minimal and fast
  • Simple test syntax
  • Runs tests concurrently
  • Enforces writing atomic tests
  • No implicit globals
  • Isolated environment for each test file
  • Write your tests in ES2015
  • Promise support
  • Generator function support
  • Async function support
  • Observable support
  • Enhanced asserts
  • Optional TAP output
  • Clean stack traces

Example test syntax

import test from 'ava';

test(t => {
    t.is(foo(), 'foo');
});
209 questions
2
votes
2 answers

Ava testing image-loading with promise: promise returned by test never resolved

I want to test my promise function to load an image, the piece of code looks like this: function imagePromise() { return new Promise((resolve, reject) => { const img = new Image(); img.addEventListener('load', () => resolve(true)); …
TotomInc
  • 613
  • 1
  • 7
  • 21
2
votes
0 answers

Animating text in run tool window

I'm using PhpStorm with a Laravel project and have set up a few basic JS tests using AVA. They all work fine when I run them in the command line. e.g.: example.text.js import test from 'ava'; test('just a mockup', async (t) => { let i = 1; …
apokryfos
  • 38,771
  • 9
  • 70
  • 114
2
votes
0 answers

Unit testing Javascript code with 3rd party libraries

I have a problem figuring out how to provide code coverage for some of my JS code where a function has within it a call to a 3rd party function that takes a callback as a parameter: function handleAuthentication () { let path =…
user2360062
  • 663
  • 2
  • 7
  • 19
2
votes
1 answer

AVA: does not show failed tests within a timeout, only passed

Any output method I use with AVA, e.g. Verbose, a reporter, or its default, always outputs the passed tests, but never the failed tests. It's becoming increasingly difficult to figure out which tests failed and why (without process of elimination,…
user860511
2
votes
1 answer

Dynamic testing with AVA

I'm looking to run ava programmaticaly, so my script would be able to run some ava tests with a dynamic argument (an URL actually). My goal is to run programmaticaly the same ava test file on a list of dynamic (from user-input) URL, and then, get…
tmos
  • 323
  • 1
  • 3
  • 13
2
votes
0 answers

How to use sinon.stub with ava?

Any suggestion how to use Sinon with ava ? when I run ava, stub.called is always false target.js const foo = () => { bar() } const bar = () => { } module.exports = { foo, bar } target.test.js import test from 'ava'; import sinon from…
Sing
  • 3,942
  • 3
  • 29
  • 40
2
votes
1 answer

Cannot find module at AVA test

I am trying to setup the AVA at my react project. So I added this code into my package.json: "ava": { "babel": "inherit", "register": [ "babel-register", "./test/helpers/browser-env.js", "ignore-styles" ] } …
Alessander França
  • 2,697
  • 2
  • 29
  • 52
2
votes
0 answers

Using AVA with jsdom, load and execute remote scripts

I'm writing a test with AVA and jsdom. This works: const rp = require('request-promise-native') const jsdom = require('jsdom') const {JSDOM} = jsdom const url = 'http://localhost:8000' rp(url).then((body) => { const options = { url: url, …
cg433n
  • 729
  • 1
  • 6
  • 10
2
votes
0 answers

How should I mock out react-native-extended-stylesheet in Mockery.js?

I have started using ava.js in my react native project. I have an AVA setup file that looks like this (from the Ignite starter project): import mockery from 'mockery'; import m from 'module'; // inject __DEV__ as it is not available when…
sinewave440hz
  • 1,265
  • 9
  • 22
2
votes
3 answers

How can I use ava's t.throws to test the error message of a function that returns a Promise?

I have a function that returns a Promise. I want to create a test for it that requires it to reject with a specific error message in order for it to pass. I've created some example tests to demonstrate what I mean: import test from 'ava'; const…
mickdekkers
  • 640
  • 2
  • 11
  • 16
2
votes
1 answer

Why does ava fail comparing list of objects and list of object literal?

I'm using the deepEqual assertion, but my test fails Test test('should return list of printers', t => { const clipboard = filter.asClipboardContent(scan); t.is(clipboard, [ {hostname: '10.0.1.1', port: '9100', description: 'HP…
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
2
votes
1 answer

Testing es5 with es6 testing framework (AVA)

I have an existing project written ecmascript5. The project has no tests and I would like to add. I used jasmine & mocha lightly (not lately...) and now I read about AVA (es6 out of the box)+Sinon and I really like it and I would like to try…
Gal Ziv
  • 6,890
  • 10
  • 32
  • 43
2
votes
1 answer

React Native unit testing with ava

I've tried following the simple setup from here regarding unit testing js code with AVA, but I am doing something wrong because the setup doesn't seem to be taken into consideration. Exception: ReferenceError: __DEV__ is not defined at…
Stefan Turcanu
  • 904
  • 9
  • 13