Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testAll function to generate tests from a list of inputs #12

Merged
merged 3 commits into from
Oct 5, 2017

Conversation

glennsl
Copy link
Owner

@glennsl glennsl commented Sep 21, 2017

Fixes #11

Went for a testAll function instead of expectAll/expectForEach/expectMany. While this restricts the design possibilities a bit, the major benefit is that it will continue to test the remaining inputs if any of the inputs fail, which is definitely worth it IMO.

cc @frankwallis, would you like to test this out to see how it fits before I merge?

external describe : string -> (unit -> unit) -> unit = "describe.only" [@@bs.val]
end

module Skip : sig
external test : string -> (unit -> 'a A.t) -> unit = "test.skip" [@@bs.val]
external testAsync : string -> (('a A.t -> unit) -> unit) -> unit = "test.skip" [@@bs.val]
external testPromise : string -> (unit -> 'a A.t Js.Promise.t) -> unit = "test.skip" [@@bs.val]
val testAll : string -> 'a list -> ('a -> 'b A.t) -> unit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be external?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it should

@frankwallis
Copy link

Thanks for doing this - I have updated some of the tests to use testAll see https://github.com/frankwallis/redouble/blob/reason/src/model/game/__tests__/boardTests.re#L36

It looks pretty good to me, the only slightly strange thing is that the assertions now come before the setup, ie the list of bids and messages is fed into the function which then creates the board in the right state and performs the test. This setup will presumably be done for each assertion whereas previously it was only being done once.

I am seeing some new errors when running the other tests, I'm not sure what they are related to, and I have to go to work now...

Expected is not a string
      
      at new StringContaining (node_modules/expect/build/asymmetric_matchers.js:191:13)
      at Function.Object.<anonymous>.exports.stringContaining.expected [as stringContaining] (node_modules/expect/build/asymmetric_matchers.js:241:1)
      at assert_ (node_modules/bs-jest/lib/js/src/jest.js:141:54)
      at Object.<anonymous> (node_modules/bs-jest/lib/js/src/jest.js:168:11)

@frankwallis
Copy link

FYI I resolved the error above by changing my Jest configuration from

  "testMatch": [
    "<rootDir>/src/**/*Tests.{re,js}"
  ],

to

  "testMatch": [
    "<rootDir>/src/**/*Tests.{re}"
  ],

@glennsl
Copy link
Owner Author

glennsl commented Oct 1, 2017

Hmm, that's a weird error and solution. Not sure what that's all about, so let's just ignore it and hope it goes away ;)

You could just wrap the tests in a describe and do the setup there, couldn't you?

@frankwallis
Copy link

agree it was a weird error :)

I could wrap all the tests in a describe but then it seems like describe is becoming test and test is becoming expect which is odd for existing jest users.

@glennsl
Copy link
Owner Author

glennsl commented Oct 2, 2017

I don't see why that'd be odd. beforeEach and afterEach aren't functions you'd call inside a test.

@glennsl glennsl merged commit 109465b into master Oct 5, 2017
@glennsl glennsl deleted the testAll branch October 5, 2017 16:56
@glennsl glennsl mentioned this pull request Dec 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants