mercredi 12 avril 2017

Testing JS files using Karma and Mocha

There is currently no front end unit testing going on and I want to change that. I've had some experience of Karma and Mocha using the Expect library when I've been doing React dev work in the past, so I was planning on sticking to that.

I'm nearly there in so far as I can npm test from the CLI and I get a passing test from any single file with a .test.js extension. That's great. However, currently I'm only testing the code written in each file. I want to have a test file for each JS file which will loads said JS file and perform assertions on it. I thought that this would work:

sampletest.test.js

var expect = require('expect');

var sampletest = require('../../js/sampletest.js');

describe('sampletest', function() {
  it('should exist', () => {
    expect(myee-form).toExist();
  });
});

However, I'm getting a You may need an appropriate loader to handle this file type. error. I don't really understand what's causing this - my assumption was that I could just reference any JS file and then write tests for it? Any suggestions?

Aucun commentaire:

Enregistrer un commentaire