{"library":"should","title":"should.js BDD Assertions","description":"should.js is an expressive, BDD-style assertion library for JavaScript, designed to be framework-agnostic and provide helpful error messages. It is currently at version 13.2.3 and maintains an active release schedule with frequent patch and minor updates. A key differentiator is its default behavior of extending `Object.prototype` with a non-enumerable `should` getter, enabling `(value).should.be.something` syntax. For environments where `Object.prototype` extension is undesirable, it offers an alternative function-style API, `should(value).be.something`. The library ships with TypeScript type definitions, though specific import patterns have seen minor adjustments across versions. It aims for readability and clear test code.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install should"],"cli":null},"imports":["import 'should';\n// or for CommonJS:\nconst should = require('should');","import should from 'should/as-function';\n// or for CommonJS:\nconst should = require('should/as-function');","import * as should from 'should';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import 'should'; // Or `const should = require('should');` for CommonJS to get global assertions\n\n// Using the Object.prototype extension (default behavior)\nconst user = {\n    name: 'Alice',\n    age: 30,\n    isActive: true,\n    tags: ['developer', 'tester']\n};\n\nuser.should.have.property('name', 'Alice');\nuser.age.should.be.a.Number().and.be.exactly(30);\nuser.tags.should.have.lengthOf(2).and.containEql('developer');\nuser.isActive.should.be.true();\n\n// Using the function-style API (without Object.prototype modification)\nimport shouldAsFunction from 'should/as-function'; // Or `const shouldAsFunction = require('should/as-function');`\n\nshouldAsFunction(null).not.be.ok();\nshouldAsFunction(undefined).not.exist();\nshouldAsFunction(user.name).be.exactly('Alice');\n\n// Example for async assertions (assuming a promise-returning function)\nasync function fetchData(id: number): Promise<any> {\n    if (id === 1) return { id: 1, value: 'data' };\n    throw new Error('Not found');\n}\n\n(async () => {\n    try {\n        const result = await fetchData(1);\n        shouldAsFunction(result).be.an.Object().and.have.property('value', 'data');\n    } catch (err: any) {\n        shouldAsFunction(err).not.exist(); // This path should not be taken\n    }\n\n    try {\n        await fetchData(2);\n    } catch (err: any) {\n        shouldAsFunction(err).be.an.Error().and.have.property('message', 'Not found');\n    }\n})();","lang":"typescript","description":"Demonstrates both the default `Object.prototype` extended assertion style and the explicit function-style `should()` API for various data types and asynchronous operations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}