Git Product home page Git Product logo

mocha-given's People

Contributors

greenkeeperio-bot avatar rendro avatar theludd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mocha-given's Issues

And after Then should not rerun setup

I use jasmine-given at work (and have even worked with Justin Searls on writing some parts of it), and one of the fundamental goals is to only run setup (Given, When) once per Then. I've noticed in my tests using mocha-given that

Then -> testSomething()
And -> testSomethingElse()

will run all Givens and Whens twice. Which kind of defeats the purpose. Now, to only run setup once, instead of getting the nice formatting of cascading Ands, I have to put everything in one giant Then block. If you check out https://github.com/searls/jasmine-given/blob/master/app/js/jasmine-given.coffee#L50 and https://github.com/searls/jasmine-given/blob/master/app/js/jasmine-given.coffee#L82, the subsequentThen mechanism tacks And functions on so that they're executed as part of the same it statement.

In other words I want to do something like:

Given -> @foo = 'bar'
When -> @subject.test()
Then -> expect(@foo).to.equal 'not bar'
And -> expect(@subject.aSpiedOnMethod).to.have.been.called
And -> expect(@someOtherStuff).to.have.happened()

and have the Given and When run once instead of three times.

I'm willing to work on this (or work on this with you) if you want.

Return value should strictly equal false for test to fail

jasmine-given checks the return values of Then and And functions as a part of the test. However the test only fails of the return value is strictly false. That way you can write code such as:

When -> @result = 1 + 2
Then -> @result == 3

I noticed that this is not the behaviour of mocha-given which seems to check if the return value is "truthy".

Since CoffeeScript implicitly returns the last statement in a function it might sometimes be something else than just true or false which makes the jasmine-given approach a good one. Can this be changed?

Native ES2016 timeout with Then

Using Node 4.2.

This works:

Then(function () { expect(2).to.equal(2) })

This times out:

Then(() => expect(2).to.equal(2))

This works:

Then(done => {
  expect(2).to.equal(2)
  done()
})

Promise support

Mocha now has promise support. Would it be possible to also add it to mocha-given?
In mocha i can write:

describe 'myPromiseFunction', ->

  beforeEach -> someAsyncSetup()

  it 'shoud return "foo" async', -> 
    myPromiseFunction().then (result) ->
      result.should.equal 'foo'  

It would be awesome if mocha-given supported this:

describe 'myPromiseFunction', ->

  Given -> someAsyncSetup()
  When -> myPromiseFunction().then (@result) =>
  Then -> @result == 'foo'

Peer dependency problem

A lot of times when I install mocha-given, I get this:

npm ERR! peerinvalid The package mocha does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants mocha@~1.16.0

but the version of mocha I'm using is 1.16.2 . . . soooooo, it should work (unless I really misunderstand semver). I can usually fix this locally by cd node_modules/mocha-given followed by npm install. However, that fix doesn't work on travis, even with something like:

install:
  - "npm install"
  - "cd node_modules/mocha-given && npm install"

because npm returns a code on a failed peer dependency, so travis just aborts immediately.

It's worth mentioning that I'm specifically using a branch on a fork of mocha (which is the reason I haven't updated mocha-given also). The version is right (1.16.2), but maybe peer dependencies are weird with forks and/or branches (so this might just be an npm bug, but I thought I'd start here). Here's the relevant package.json entry:

  "devDependencies": {
    "coffee-script": "~1.7.1",
    "underscore": "~1.6.0",
    "mocha": "git://github.com/tandrewnichols/mocha.git#suppress-stack",
    "mocha-given": "~0.0.18",
    "indeed": "~1.0.1"
  },

And the actual installed version of that suppress-stack branch:

AndrewNichols:safe-obj$ cat node_modules/mocha/package.json | grep version
  "version": "1.16.2",

Any insight into this?

Browser distribution should be wrapped in an IIFE

Firstly, the browser distribution of mocha-given (/browser/mocha-given.js) is very much appreciated!

However, the compiled JavaScript currently pollutes the browser's global scope with all of the module's variables. I believe that compiling CoffeeScript without the --bare option should fix that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.