Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vitaly-rudenko/qilan
JavaScript mocking framework inspired by Mockito.
https://github.com/vitaly-rudenko/qilan
jasmine javascript mockito package testing
Last synced: 9 days ago
JSON representation
JavaScript mocking framework inspired by Mockito.
- Host: GitHub
- URL: https://github.com/vitaly-rudenko/qilan
- Owner: vitaly-rudenko
- License: gpl-3.0
- Created: 2021-01-16T09:13:01.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-18T22:33:32.000Z (almost 4 years ago)
- Last Synced: 2024-11-08T22:26:24.906Z (2 months ago)
- Topics: jasmine, javascript, mockito, package, testing
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Qilan concept
## Mocks
### Creating a mock from a class
```js
class Dog {
bark(type) { /* ... */ }
async woof() { /* ... */ }
}const dog = mock(Dog);
```## Spies
### Creating a spy
```js
const bark = spy();
const woof = when().resolve();const meow = when(() => spy()).do('m-m-meow');
const purr = when(() => spy('purr?')).return('purr!');
```### Spying on all methods & properties
```js
spy(dog);
```## Custom behavior
### Simple
```js
when(() => dog.name).return('Cooper');
when(() => dog.bark()).do(() => console.log('bark!'));
```### Multiple calls
```js
when(() => dog.name).return('Cooper', 'Baxter');
when(() => dog.bark()).do(
() => console.log('odd bark!'),
() => console.log('even bark!'),
);console.log(dog.name, dog.name, dog.name); // Cooper Baxter Cooper
console.log(dog.bark(), dog.bark(), dog.bark()); // odd bark! even bark! odd bark!
``````js
when(() => dog.name).returnOnce('Cooper', 'Baxter');
when(() => dog.bark()).doOnce(
() => console.log('first bark!'),
() => console.log('second bark!'),
);console.log(dog.name, dog.name, dog.name); // Cooper Baxter undefined
console.log(dog.bark(), dog.bark(), dog.bark()); // first bark! second bark! undefined
```### Arguments
```js
when(() => cat.meow()).do(type => 'meow');
when(() => cat.meow(anyArgs())).do(type => 'm-m-meow');when(() => dog.bark(any(String))).do(type => `${type} bark!`);
when(() => dog.bark(any(Number))).do(count => `bark #${count}!`);
```## Expectations
### Equality assertion
```js
same(dog.breed, 'Doge');
equal(dog.age, any(Number));
```### Call expectations
```js
called(() => dog.bark(anyArgs()));
calledOnce(() => dog.woof());
calledTimes(5, () => cat.meow(true));
notCalled(() => cat.purr(any(String), any()));
```