Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Allow simpler tests for error.code

Offen
#166 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
javascript
Bereich
testing-qa

Rechercherichtung

Beginne damit, die Assertion-Einstiegspunkte throw() und reject() sowie das vorhandene Verhalten von contain() zu finden. Füge Testabdeckung für eine optionale Nachricht und das vorgeschlagene Fehler-Eigenschaftenobjekt einschließlich des ERR_INVALID_ARG_TYPE-Beispiels hinzu und bestätige, dass beide Assertions ihr aktuelles Verhalten beibehalten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

feature
Support plan
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no
Context
  • node version: any
  • module version: 8.0.3
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:
What problem are you trying to solve?

To test for the .code property attached to node errors (instead of .message) that are not fixed).

Currently I have to do this manually, eg. for throw():

const Code = require('code');
const expect = Code.expect;

const err = expect(() => process.chdir(42)).to.throw(TypeError);
expect(err).to.contain({ code: 'ERR_INVALID_ARG_TYPE' });

// or as one-liner
expect(expect(() => process.chdir(42)).to.throw(TypeError)).to.contain({ code: 'ERR_INVALID_ARG_TYPE' });
Do you have a new or modified API suggestion to solve the problem?

Add a third has parameter to throw() and reject(), which takes an object which is passed to a contain() test. Also make the message optional (works since it uses a string and type must be instanceof Error). Eg.

expect(() => process.chdir(42)).to.throw(TypeError, { code: 'ERR_INVALID_ARG_TYPE' });
Vorherrschende Sprache
JavaScript
Sterne
231
Forks
75
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus hapijs/code

Alle Issues in hapijs/code

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.