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
93
votes
7 answers

Error: *.default is not a constructor

I get the following error, when testing some javascript code, transpiled from a typescript file. Here is the error: Error: _mapAction2.default is not a constructor Here is the line of code that caused the error: var mapAction = new…
ChristopherMortensen
  • 1,093
  • 2
  • 8
  • 10
28
votes
3 answers

ava: SyntaxError: Unexpected token import

So ava comes with build-in ES2015 support, which works fine for my actual test files. However, when I do import {newUser, createUser, login} from './helpers/user'; I can't use import and export in the helper file, I then…
rweng
  • 6,736
  • 7
  • 27
  • 30
23
votes
2 answers

How to setup jsdom when working with jest

I'm trying to migrate from AVA to Jest. In AVA you can set ava.setup, in which you set the jsdom environment. For example, creating the DOM structure and doing necessary polyfills (localStorage). How do I accomplish that in Jest? Currently, I'm…
Gal Ziv
  • 6,890
  • 10
  • 32
  • 43
13
votes
3 answers

Stub an export from a native ES Module without babel

I'm using AVA + sinon to build my unit test. Since I need ES6 modules and I don't like babel, I'm using mjs files all over my project, including the test files. I use "--experimental-modules" argument to start my project and I use "esm" package in…
Jim Jin
  • 1,249
  • 1
  • 15
  • 28
12
votes
1 answer

Integration Tests Against a Database - AVA

After writing unit tests, i'm facing with Integration tests, which consist of testing the library against a database (rethinkdb). Each testcase has to be independent between each other, and the database will be cleared after each test, so that they…
Fabrizio Fenoglio
  • 5,767
  • 14
  • 38
  • 75
11
votes
3 answers

How to pause the test script for 3 seconds before continue running it? Playwright

I'm running a test called create admin. The test will first create admin, then check if the admin was created successfully. In the script, I have a part of code where I want to wait for 3 seconds before continuing because whenever the submit button…
jialeee17
  • 601
  • 2
  • 7
  • 12
9
votes
0 answers

How to mock browser specific property `window.location.origin` with AVA

Context I have Frontend React+Webpack app consuming backend APIs. My Webpack setup depends on window.location.origin the property, for setting up and deployment processes. Currently, I'm using Karma testrunner and am trying to replace it with AVA…
9
votes
2 answers

Why Doesn't (JS Testing Library) AVA Have "Suites" (or Any Other Groupings)?

I'm looking at the AVA test runner, and it's concurrency feature seems pretty compelling. However, I'm used to Mocha, where you can organize your tests like so: describe('Some Class', () => { describe('#someMethod', () => { …
machineghost
  • 33,529
  • 30
  • 159
  • 234
8
votes
1 answer

Writing unit tests for method that uses jwt token in javascript

I have been trying to write unit test in javascript for the method which uses jwt token validation. So the results are fetched only if the token is valid. I want to mock the jwt token and return results. Is there any way to do it ? I tried using ava…
Johnson Samuel
  • 2,046
  • 2
  • 18
  • 29
8
votes
1 answer

Tests are passing, coverage is not showing

I'm trying to get nyc ava and babel to all place nice together. I was having an issue where async / await branches were showing as not covered, so this was working, I'm having trouble integrating the babel-plugin-istanbul plugin for tests. I have…
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
8
votes
5 answers

Testing: mocking node-fetch dependency that it is used in a class method

I have the following situation: A.js import fetch from 'node-fetch' import httpClient from './myClient/httpClient' export default class{ async init(){ const response = await fetch('some_url') return…
8
votes
1 answer

Test computed property in Vue.js using AVA with Avoriaz

I'm trying to test a computed property of a Vue.js component using AVA and Avoriaz. I can mount the component and access the data properties fine. When I try an access a computed property, the function doesn't seem to have scope to the data on that…
Ryan Gill
  • 1,728
  • 2
  • 13
  • 27
8
votes
5 answers

ES6 import for 'ava' test not working

I followed the docs to create my first test using ava but it doesn't seem to run properly. I get the error below. I tried adding import 'babel-register'; at the top of the file, and it works, but only if I run one specific test file. e.g. ava…
Clement
  • 4,491
  • 4
  • 39
  • 69
7
votes
1 answer

Unit testing Vue components that rely on a global event bus

I declare an event bus in my global app.js like so: window.Event = new Vue(); The component looks like export default { data() { return { hasError: false, zip: '', }; }, methods: { …
mazedlx
  • 1,405
  • 17
  • 24
7
votes
2 answers

Problems with ava asynchronous tests when stubbing with sinon

I have a couple of tests I'd like to run on the .then and .catch blocks of one of my dependencies. import test from 'ava'; import sinon from 'sinon'; // Fake dependency code - this would be imported const myDependency = { someMethod: () =>…
sak_to
  • 399
  • 4
  • 13
1
2 3
13 14