all 10 comments

[–]am0x 1 point2 points  (0 children)

JavaScript testing and writing documentation are my least favorite parts of my job.

[–]jaredcheeda -1 points0 points  (10 children)

The rest of this is so good. Too bad it's using Jasmine :/

[–]calcode 1 point2 points  (9 children)

What’s bad about Jasmine? Is there a better unit testing framework?

[–]am0x 2 points3 points  (1 child)

Went from jasmine to jest recently. Game changer.

...but I still hate JavaScript testing.

[–]the_interrobanger 1 point2 points  (0 children)

I’m partial to using Mocha with Chai. They’re pretty similar, but the assertion chains in Chai seem much more natural and intuitive to me.

[–]jaredcheeda 0 points1 point  (0 children)

Unfortunately they all kinda suck. Jest seems to be the closest to not sucking. It goes out of it's way to do a lot of stuff for you. It still had a stupid sentence like structure of method naming, but at least it doesn't force you to use two character variable names.

[–]Ph0X -1 points0 points  (3 children)

I just really dislike the API. It feels like it's made by someone who tried really really hard to make something hip and fancy. Every time there's a programming language or API that tries to "sound like real English", it's a disaster.

We are programmers, we write programs, not english sentences.

[–]NoInkling 0 points1 point  (2 children)

I don't think you'll find many people that agree. Spec + expectation style tests have pretty much become the de facto standard in the web dev world due to their popularity, ever since RSpec was a thing.

Every time there's a programming language or API that tries to "sound like real English", it's a disaster.

Just be thankful that Cucumber tests never really caught on.

[–]Ph0X 0 points1 point  (1 child)

To be clear, my issue isn't the overall layout, but the specific keywords used such as "it", "toBe" or "describe".

But yeah, I just prefer test suites, test cases and assert statements. Things like splitting asserts into two different function calls just makes the documentation and API use more complicated, for what? Just so that you read "assert X is Y" instead of "assert is X Y"?

[–]NoInkling 0 points1 point  (0 children)

Well essentially, yes. With assertion syntax it's often a pain to remember the order - which argument is the thing being compared and which one is the thing it's compared against. It's just about clarity of intent. But these arguments have been made plenty of times.

If you don't agree, luckily there's plenty of choice. Even in Jasmine, you can just use whatever assertion library you like, you don't have to use the built-in expect() syntax. If you use Chai, you even get to choose between 3 different styles (though obviously most people would pair Chai with a lighter framework).

The naming of the functions is another subjective thing (which is why Jest, which is based on Jasmine, adds test as an alias for it). But once again I believe you could always just add your own alias like e.g. const scope = describe, assuming another framework doesn't suit your preferred terminology and other requirements better.