New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

earljs

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

earljs - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

dist/ExecutionCtx.d.ts

2

dist/Expectation.d.ts
import { AutofixType } from './autofix';
import { ValidationResult } from './validators/common';
import { toBeExhausted } from './validators/mock';
import { toEqual } from './validators/toEqual';

@@ -20,3 +21,4 @@ import { toLooseEqual } from './validators/toLooseEqual';

toThrow: typeof toThrow;
toBeExhausted: typeof toBeExhausted;
}
export declare function satisfy<T extends (...args: any[]) => ValidationResult>(validator: T): T;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mock_1 = require("./validators/mock");
const toEqual_1 = require("./validators/toEqual");

@@ -15,2 +16,3 @@ const toLooseEqual_1 = require("./validators/toLooseEqual");

this.toThrow = satisfy(toThrow_1.toThrow);
this.toBeExhausted = satisfy(mock_1.toBeExhausted);
}

@@ -17,0 +19,0 @@ // modifiers

export * from './expect';
export { strictMockFn } from './mocks/strictMock';
export { looseMockFn } from './mocks/looseMock';

@@ -7,1 +7,5 @@ "use strict";

__export(require("./expect"));
var strictMock_1 = require("./mocks/strictMock");
exports.strictMockFn = strictMock_1.strictMockFn;
var looseMock_1 = require("./mocks/looseMock");
exports.looseMockFn = looseMock_1.looseMockFn;

2

dist/validators/toThrow.d.ts
import { Expectation } from '../Expectation';
import { ValidationResult } from './common';
export declare function toThrow<T extends Function>(this: Expectation<T>, expectedMsg?: string): ValidationResult;
export declare function toThrow<T extends () => any>(this: Expectation<T>, expectedMsg?: string): ValidationResult;

@@ -15,3 +15,3 @@ {

"license": "MIT",
"version": "0.0.6",
"version": "0.0.7",
"main": "./dist/index.js",

@@ -18,0 +18,0 @@ "types": "./dist/index.d.ts",

![Earl](https://raw.githubusercontent.com/krzkaczor/earl/master/docs/images/gh-cover.png)
<p align="center">
<p align="center">Ergonomic, modern and type-safe assertion library</p>
<p align="center">Ergonomic, modern and type-safe assertion library for TypeScript</p>
<p align="center">Brings good parts of <b>Jest</b> back to good ol' <b>Mocha</b></p>

@@ -24,5 +24,5 @@ <p align="center">

const response = await apiCall()
// ...
expect(response).toEqual({ body: { trimmed: true, timestamp: expect.any() } })
expect(response).toEqual({ body: { trimmed: true, timestamp: expect.a(String) } })
```

@@ -35,3 +35,3 @@

TypeScript becomes more and more popular, it became evident that some things about writing assertions could be improved.
**Earl** is an effort to bring a little bit of innovation in the space of assertion libraries.
**earl** is an effort to bring a little bit of innovation in the space of assertion libraries.

@@ -41,3 +41,3 @@ ### Why not just Jest?

I really enjoy some of the Jest's features — that's what inspired this library in the first place. However, I really
hate others. Simply put, Jest feels too [magical](https://github.com/facebook/jest/issues/4414) and
hate others. Jest feels too [magical](https://github.com/facebook/jest/issues/4414) and
[full](https://github.com/facebook/jest/issues/2441) of [bugs](https://github.com/facebook/jest/issues/8688) for my

@@ -47,2 +47,4 @@ taste. Lots of its complexity comes from the features that I don't even care about like modules mocking or test

Simply put, **Jest takes control away from you, Mocha puts you in charge**.
## Features

@@ -60,3 +62,3 @@

timestamp: '05/02/2020 @ 8:09am (UTC)',
}).toEqual({ abc: 'abc', timestamp: expect.anyString() })
}).toEqual({ abc: 'abc', timestamp: expect.a(String) })
```

@@ -100,2 +102,3 @@

parameterless function.
- `toBeExhausted()` - checks if given mock is exhausted. Works both with strict and loose mocks.

@@ -106,5 +109,6 @@ ### Matchers

- `anything` - matches anything
- `anything()` - matches anything
- `a(class)` - matches any instance of a class. Works as expected with primitives like String, Number etc. Use
`a(Object)` to match any object (won't match null)
`a(Object)` to match any object (won't match null). Note: it doesn't work with TypeScript types because they are
erased from the output - you need a JS class.
- `stringContaining(substring)` - matches any string containing given substring

@@ -116,2 +120,48 @@

### Mocks
Currently earl features two types of mocks:
- `strictMocks` are well defined mocks with expected calls and responses defined up front
- `looseMocks` are more traditional mocks similar to sinon/jest.
Both types of mocks are automatically verified (`isExhausted` check) if test runner integration is enabled.
### Examples:
```js
import { expect, strictMockFn } from 'earljs'
const mock = strictMockFn<[number], string>()
mock.expectedCall(1).returns('a')
mock.expectedCall(2).returns('b')
mock.expectedCall(earl.a(Number)).returns('c')
expect(mock(1)).toEqual('a')
expect(mock(2)).toEqual('b')
expect(mock(5)).toEqual('c')
// unexpected call
expect(mock(1)).toThrow()
// note: use test runner integration to auto verify mocks and avoid writing this check by hand
expect(mock).toBeExhausted()
```
### Test runner integration
By integrating with a test runner you get:
- automatic mocks verification after each test
Currently only integration with mocha is supported. To enable, simply require `earljs/mocha` with mocha, you can put it
in `.mocharc.js`:
```js
module.exports = {
require: ['earljs/mocha'],
// ...
}
```
## Project state

@@ -118,0 +168,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc