Socket
Socket
Sign inDemoInstall

expect

Package Overview
Dependencies
0
Maintainers
1
Versions
235
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    expect

the essential JavaScript test library


Version published
Maintainers
1
Install size
3.73 kB
Created

Package description

What is expect?

The 'expect' npm package is a library for writing test assertions. It is commonly used in conjunction with testing frameworks like Jest or Mocha to validate the behavior of JavaScript code. It provides a range of assertion types and matchers that allow developers to write expressive and readable tests.

What are expect's main functionalities?

Basic Assertions

This feature allows you to assert that a value matches exactly what you expect. The 'toBe' matcher compares with ===.

expect(2 + 2).toBe(4);

Object Property Assertions

With this feature, you can assert that an object has a specific property with a certain value. The 'toHaveProperty' matcher checks for the existence and value of a property in an object.

expect({ name: 'Alice', age: 30 }).toHaveProperty('name', 'Alice');

Exception Testing

This feature is used to test if a function throws an exception when it is executed. The 'toThrow' matcher is used to assert that an error is thrown with a specific message.

expect(() => { throw new Error('failure'); }).toThrow('failure');

Array Containment

This feature allows you to assert that an array contains a specific item. The 'toContain' matcher checks if an array includes the expected item.

expect(['Alice', 'Bob', 'Eve']).toContain('Bob');

Asynchronous Assertions

This feature enables you to write assertions for asynchronous code. The 'resolves' matcher waits for a promise to resolve and then checks the resolved value.

expect(Promise.resolve('success')).resolves.toBe('success');

Other packages similar to expect

Readme

Source

expect

the essential JavaScript test library

API

expect value is ...

  • deepEqual (value, expected, message)
  • equal (value, expected, message)
  • false (value, message)
  • true (value, message)

License

(The MIT License)

Copyright (c) 2011 Enrico Marino <enrico.marino@email.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Last updated on 03 Dec 2011

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc