0

I am using AVA as testing with node and javascript.

On test.js

import test from 'ava';
import {valid, output, input} from './dependency.js';

test("Input is not a Empty String", t => {
    t.not(input, ''); t.pass();
})

test("Correct output", t => {
    var testInput = ['KittenService: CameCaser', 'CamelCaser: '];
    var expected = 'CamelCaser, KittenService';
    var actual = output;
    t.deepEqual(actual, expected, "Result did match");
})

On first test it passes even though my

var input = '';

Also on my second test it throws:

t.deepEqual(actual, expected, "Result did match")
              |       |
              |       "CamelCaser, KittenService"
              undefined

on dependency.js

module.exports = {valid, input, output};
var input = '';
var output = [];

I do have value of output after function but it seems like on test.js it doesn't take either input or output value from dependency test. I am not exactly sure how to fix this problem.

Yh1234
  • 141
  • 2
  • 12

1 Answers1

1

AVA uses Babel to compile the import statements. Since dependency.js isn't created using Babel the module.exports object is treated as a default export when importing.

Do this instead:

import test from 'ava';
import dependency from './dependency.js';

const {valid, output, input} = dependency;

test("Input is not a Empty String", t => {
    t.not(input, '');
})

test("Correct output", t => {
    var testInput = ['KittenService: CameCaser', 'CamelCaser: '];
    var expected = 'CamelCaser, KittenService';
    var actual = output;
    t.deepEqual(actual, expected, "Result did match");
})

P.S. You usually do not need t.pass().

Mark Wubben
  • 3,329
  • 1
  • 19
  • 16
  • Hey Mark I changed the code and it is giving me same result. – Yh1234 Jan 30 '17 at 22:49
  • My package.json code `{ "name": "assessment", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "ava" }, "author": "", "license": "ISC", "devDependencies": { "ava": "^0.17.0" } }` – Yh1234 Jan 30 '17 at 22:54
  • Figured out I had to put my variables inside the dependency function then your method worked. – Yh1234 Jan 30 '17 at 23:20