0

I'm new to Node and to TDD and I'm trying to get my head around how to create tests locally for Codewars JS Katas.

I've got as far as making var cw = require('kata-test-framework-js'); work by using this answer: https://stackoverflow.com/a/18778516/3042018

I can make is work like this: cw.Test.assertSimilar([1,2,2],[1,2,3]); but I'd like to be able to use the exact test code from the katas - i.e. without having to prefix everything with cw.

Can anyone explain how to do this please?

Community
  • 1
  • 1
Robin Andrews
  • 3,514
  • 11
  • 43
  • 111

1 Answers1

1
var Test = require('kata-test-framework-js').Test

Should do the trick

Andy Macleod
  • 2,889
  • 1
  • 13
  • 16
  • It's all about how you name your variables and how you export them. In this case the export is an object **inside** of which there is a `Test`. So if you simply require the package you need to access it. Or you can save a reference during requirement and then use it from there on as a shorthand. It's still a local variable, but with the same name, which makes your life a bit easier. It's a common thing to do. – Andrey Popov Nov 11 '16 at 08:28
  • Thanks for the better explanation @AndreyPopov! – Andy Macleod Nov 11 '16 at 08:31
  • Thanks for that. It turns out that cw contains several methods: `{ Test: 1, describe: [Function], it: [Function], before: [Function], after: [Function] }` Is there a way to use them all without the `cw.`? Maybe I need 5 separate require statements? – Robin Andrews Nov 12 '16 at 09:30
  • you could require the package and then declare variables for each property var cw = require('kata-test-framework-js'); var test = cw.Test; var it = cw.it; var before = cw.before; and so on – Andy Macleod Nov 12 '16 at 10:22