hirezio / given

A monorepo for jasmine / jest addons that help you clean up your microtests by breaking them into a Given / When / Then structure.
MIT License
21 stars 4 forks source link

ReferenceError: beforeEach is not defined #2

Closed fizdalf closed 4 years ago

fizdalf commented 4 years ago

Describe the bug When adding jasmine-given to the karma.conf.js file console complains about: ERROR [config]: Error in config file! ReferenceError: beforeEach is not defined at E:\learning material\Angular Testing Basics Course\angular-testing1-llama-date\node_modules\@hirez_io\jasmine-given\temp-src\jasmine-given.ts:30:1

I'm following along with the Angular Testing Basics course and I can't move past this. It seems to me that jasmine-given is loading before jasmine is there and thus beforeEach doesn't exist at that point.

This also happens in a brand new Angular project. So I'll use that to illustrate the steps

To Reproduce Steps to reproduce the behavior:

  1. run ng new and generate a new Angular project
  2. run yarn -D add @hirez_io/jasmine-given
  3. add require('@hirez_io/jasmine-given') to the array of plugins in your karma.conf.js
  4. add "@hirez_io/jasmine-given" to the array of types in your tsconfig.spec.json
  5. run ng test and cry in a corner

Expected behavior I would expect to run ng test and for it to just work

Attached the brand new Angular project with jasmine-given ..and not working. hirezTest.zip

shairez commented 4 years ago

Hi @fizdalf !

Thanks for the report

Few things -

  1. I noticed you're missing karma- in your require statement as described here

Try adding require('@hirez_io/karma-jasmine-given') to the array instead.

  1. You didn't write it in the tests, so pay attention that you also need to add @hirez_io/jasmine-given' to theframeworksarray inkarma.conf.js(this time without thekarma-` keyword)

  2. Lastly, as written here, if your tsconfig.json has a typesRoots property, you need to add node_modules/@hirez_io to it as well...

let me know if that worked for ya

Thanks!

fizdalf commented 4 years ago

I just saw I had to add require('@hirez_io/karma-jasmine-given'), and not require('@hirez_io/jasmine-given') to the karma plugins array. 🤦 I promise a llama forced me to do it that way.

shairez commented 4 years ago

I believe you! those llamas can be intimidating sometimes... 🦙🤛😅