loading words...

Jan 08, 2019 09:16:49

JavaScript testing sucks

by @swizecteller | 200 words | 🐣 | 116💌

Swizec Teller

Current day streak: 0🐣
Total posts: 116💌
Total words: 32303 (129 pages 📄)

Today I learned that JavaScript testing absolutely sucks.

Here's what happened 👇#200wordsTIL

---

I'm building a library that converts markdown into tweets. No UI yet so it makes sense to write tests and run those. 

---

I used nwb so my project came preconfigured with Karma and everything you need for tests.

yarn test:watch 👌

---

Yesterday this worked great. Messed around with remark and got something working.

https://twitter.com/Swizec/status/1082086702926024705

---

Today, I tried to use the AWS Lambda I built 2 months ago for techletter.app to convert code blocks into Carbon screenshots.

Imagine writing a tweet with some code and it magically becomes pretty. Wonderful. 🧙‍♂️

---

And that's when all hell broke loose.

fetch undefined

😤

---

node, you see, doesn't have fetch. It doesn't have btoa either and I needed that too.

Tried node-fetch. Didn't work in my webpack'd environment. Tried node-isomorphic-fetch. That worked.

---

Now I'm importing a huge polyfill for something I won't even need just so I can run tests. That's silly.

Even had to fake the btoa() function. Just for tests. Waste of code.

---

And the coup de grace? 

Karma kills my async function before it has the chance to finish. Tests pass, sure, but without checking the result.



Originally published at twitter.com

contact: email - twitter / Terms / Privacy