Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Jest 19: Immersive Watch Mode and Test Platform Improvements (facebook.github.io)
92 points by orta on Feb 21, 2017 | hide | past | favorite | 13 comments


Can anyone explain to me why the `expect` type of assertion library caught on so much in the javascript land?

I mean how is

    expect(2).toBeLessThanOrEqualTo(3)
more readable than

    assert(2 <= 3)
Especially when we have packages like power-assert (1)

[1] https://github.com/power-assert-js/power-assert


Because:

A) It doesn't require transforms to bring you good messages.

B) <= is an "easy" case, but what about deep equality, recursive matchers[1], or snapshots[2]?

[1]: http://facebook.github.io/jest/docs/expect.html#expectobject... [2]: http://facebook.github.io/jest/docs/snapshot-testing.html


Because you get way better error reporting. Asserting on a boolean is just pass/fail, but with expect the runner tells you "got X, expected Y" which is way better.


> To use power-assert, you need to transform your test code for power-assert output.

That's a pretty big requirement.

I usually avoid the long names like that, but doing `expect(3).toEqual(4)` isn't too bad and it allows the test runner to provide really good error messages.


I think it comes from the Ruby community influence where the language and tools aim to read like natural language.


This has a couple advantages:

1. A test that reads as natural language is easy to understand. Straightforward, declarative tests are a big win IMO. 2. This allows for better test result reporting: instead of assertion failed, the utility can tell you more (expected 4 but got 3).


After coming from the iOS world, Jest is one of the most transformative tools for me when working in JavaScript. IT's super powerful, has really really useful features and is constantly being improved.

Some of the GIFs in this post show how awesome the watcher mode in the new Jest release is, I'd strongly recommend giving them a look!


Jest is so good. No additional plugins for anything you want to do.

Only part I want from jest is own .rc file.


There is an open PR for this: https://github.com/facebook/jest/pull/2445 - it may end up in the next release at this rate


Great. Would really help for bigger projects.


I didn't realize the power of Jest (and how it made everything easy to use) till I decided to re-create the functionality with Mocha (and nyc for coverage).

Took me almost half a day to an half-assed port of sorts of such an awesome tool.

(the reason I used Mocha was because it was already a dep for my integration testing and I didn't want to introduce Jest - in the end - I introduced jsdom, enzyme and nyc as well)


I've been using Jest for around 6 or so months, first because of Snapshot testing, and second because of create-react-app coming with it by default.

But an old friend who is a lot better at JS than I, still uses and loves Ava. I was wondering if anyone could come around and give me a good assessment of pros/cons between the two.


Could someone point me in the right direction for mocking? More specifically, I'm trying to mock the AWS-SDK in a Serverless project. I just can't get a grasp of it from the documentation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: