N
N
Nikita Sokolov2020-01-24 13:14:23
webpack
Nikita Sokolov, 2020-01-24 13:14:23

How to test in Webpack?

If I start messing with webpack, nothing will work in any way. It's already a rule.
In short, the essence of the problem is that I need to test with Mocha and Chai functions. How can I import them into the test file itself? For example, I have a pow function in a typescript file:

module.exports = {
  pow(num: number, extent: number): number {
    return num ** extent;
  },
};

Next, webpack compiles this into something, and as a result, in the test file, I try to import from the compiled file:
const plugin = require('../../../dist/assets/js/jquery.slider.min.js');
const mocha = require('mocha');
const chai = require('chai');

const { expect, assert } = chai;

describe('pow', () => {
  it('возводит в степень n', () => {
    assert.equal(plugin.pow(2, 3), 8);
  });
});

But when I run the tests, it shows this:
1) pow
       возводит в степень n:
     TypeError: plugin.pow is not a function
      at Context.it (src/plugin/tests/tests.js:9:25)

In short, how to import correctly? What could be the problem? Explain, please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Sokolov, 2020-01-24
@wb_by

Found a simple solution, now tests on ts:
https://journal.artfuldev.com/unit-testing-node-ap...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question