Gathering detailed insights and metrics for @teamteanpm2024/earum-quos-illum
Gathering detailed insights and metrics for @teamteanpm2024/earum-quos-illum
Gathering detailed insights and metrics for @teamteanpm2024/earum-quos-illum
Gathering detailed insights and metrics for @teamteanpm2024/earum-quos-illum
npm install @teamteanpm2024/earum-quos-illum
Typescript
Module System
Node Version
NPM Version
56.8
Supply Chain
39.6
Quality
80.3
Maintenance
100
Vulnerability
100
License
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-44.4%
5
Compared to previous week
Last month
84.2%
35
Compared to previous month
Last year
0%
549
Compared to previous year
37
A zero-animal-cruelty JavaScript testing library for async components, observable states and view-models. Based on rx-marbles, it dramatically simplifies setting up unit tests for observable streams.
People don't like writing tests... unless it's efficient and fun. If it's not fun, the result is awful and clients are unhappy. If it's not efficient but people have fun writing them, it's a business tragedy. This is especially true when complex UI and async interaction is involved, where each single unit test can get notoriously long to write and maintain.
Leaping Bunny is designed to help testing Rimmel.js components, views and view-models where complex or async logic is involved.
View-models in Rimmel.js are often plain in-out Observables (Rx Subjects, BehaviorSubjects, etc), which are best tested using with ASCII-art and Rx Marbles.
This is how easy becomes to test a component's view-model, where you click a button and it counts your clicks.
1import { observe } from '@teamteanpm2024/earum-quos-illum'; 2import viewModel from './view-model.js'; 3 4const mappings = { 5 input: { 6 C: { type: 'click' }, // Map "C" to a DOM "ClickEvent", which will be fed into the view-model 7 }, 8 output: { 9 } 10}; 11 12describe('Click Counter', () => { 13 describe('When the button is clicked', () => { 14 15 observe.it('Emit a count of clicks', viewModel, mappings, { 16 input: '---C---C--CC---C---', // Actions (C = button is clicked) 17 output: '---1---2--34---5---', // Expectations (1, 2, 3 is the output emitted each time) 18 }); 19 20 }); 21}); 22
If your state combines multiple input and/or emits multiple output streams, the easiest way is to wrap your view-model in the Rimmel.js view-model format:
1 const multiStreaamViewModel = ([inputs, outputs]) => { 2 const { input1, input2 } = inputs; 3 const { output1, output2 } = outputs; 4 5 // Business logic goes here. 6 // Process input1 and input2, emit output1, output2 7 }
This way your view-models can have an unlimited number of input and output streams, and are ready to be testen in very simple way. For instance, take a hypothetical view-model for a UI with two buttons you have to click, alternatively, 5 times each. If you do, you'll get a "You win" message in output, otherwise a "You lose".
1// multi-stream-view-model.test.js 2import { observe } from '@teamteanpm2024/earum-quos-illum'; 3import multiStreamViewModel from './multi-stream-view-model.js'; 4 5const mappings = { 6 input: { 7 C: { type: 'click' }, // Map "C" to a DOM "ClickEvent", which will be fed into the view-model 8 }, 9 output: { 10 W: 'You win', // Map "W" to a mnemonic for "You win" 11 L: 'You lose', // Map "L" to a mnemonic for "You lose" 12 } 13}; 14 15describe('Alternate clicks', () => { 16 describe('When the buttons are clicked 10 times, alternatively', () => { 17 18 observe.it('Emit a "You win" message', viewModel, mappings, { 19 inputs: { 20 input1: '---C---C--C--C---C-----', // Actions (C = button is clicked) 21 input2: '-----C---C--C--C---C---', // Actions (C = button is clicked) 22 }, 23 outputs: { 24 output1: '------------------W---', // Expectations. W when the last button is clicked. 25 } 26 }); 27 28 }); 29});
In the test above we're making sure that when input1
and input2
receive exacly 5 clicks, alternatively, then output1
emits "You win".
Want to test if you start with the second button instead? Trivial.
1 observe.it('Second button first, then emit a "You win" message', viewModel, mappings, { 2 inputs: { 3 input1: '-----C---C--C-C----C-', // Actions (C = button is clicked) 4 input2: '-C-----C--C--C---C---', // Actions (C = button is clicked) 5 }, 6 outputs: { 7 output1: '------------------W-', // Expectations. W when the last button is clicked. 8 } 9 });
So, what about other cases, when the alternative sequence is not respected?
1 observe.it('Second button first, then emit a "You win" message', viewModel, mappings, { 2 inputs: { 3 input1: '--C--C------C-C----C-', // Actions (C = button is clicked) 4 input2: '-C-----CCCC--C---C---', // Actions (C = button is clicked) 5 }, 6 outputs: { 7 output1: '----L---------------', // Expectations. L when the first wrong button is clicked. 8 } 9 });
In this case, we expect output1
to notify as soon as the first wrong button is clicked.
No vulnerabilities found.
No security vulnerabilities found.