Coder Social home page Coder Social logo

Comments (4)

kt3k avatar kt3k commented on July 19, 2024

I don't think we need this. assertThrows returns the thrown error. We can assert whatever thing on it by using it. That pattern is more flexible than assertStrictThrows as we can assert about any property (like .code for DOMException or Node compat errors).

const err = assertThrows(() => someFunc());

assertEquals(err.message, "The error message");
assertEquals(err.code, "ERR_FOO_BAR");

from deno_std.

iuioiua avatar iuioiua commented on July 19, 2024

I don't think we need this. assertThrows returns the thrown error. We can assert whatever thing on it by using it. That pattern is more flexible than assertStrictThrows as we can assert about any property (like .code for DOMException or Node compat errors).

const err = assertThrows(() => someFunc());

assertEquals(err.message, "The error message");
assertEquals(err.code, "ERR_FOO_BAR");

That's easily fixed by returning the error at the end of these assertions.

The main issue these functions aim to fix is fully defining error properties in tests. This is because arguments are optional, and we only check that a message includes a string instead of equalling a string. Once test assertions are updated across the codebase, these functions ensure we check thrown/rejected errors strictly. Otherwise, parts of errors can fly under the radar within tests. I came up with this, but I'm happy to hear other solutions.

from deno_std.

kt3k avatar kt3k commented on July 19, 2024

That's easily fixed by returning the error at the end of these assertions.

I don't understand this. assertThrows currently returns the error object. assertRejects returns the promise of the error. If the user prefer to check the equality of the message, then the above example is what is recommended now. ref #2220 #2226

from deno_std.

iuioiua avatar iuioiua commented on July 19, 2024

We discussed this offline. Instead, we can create design documentation and then a tracking issue to adjust the codebase to that new convention.

from deno_std.

Related Issues (20)

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.