BVB Source Codes

in-view Show registry.check.spec.js Source code

Return Download in-view: download registry.check.spec.js Source code - Download in-view Source code - Type:.js
  1. import test from 'ava';
  2. import Registry from '../src/registry';
  3. import { inViewport } from '../src/viewport';
  4.  
  5. window.innerWidth = 1280;
  6. window.innerHeight = 700;
  7.  
  8. const opts = {
  9.     offset: {
  10.         top: 0,
  11.         right: 0,
  12.         bottom: 0,
  13.         left: 0
  14.     },
  15.     threshold: 0,
  16.     test: inViewport
  17. };
  18.  
  19. test('Registry.check updates current', t => {
  20.  
  21.     let registry = Registry([{
  22.         getBoundingClientRect() {
  23.             return {
  24.                 bottom: 1,
  25.                 left: 1,
  26.                 right: 1,
  27.                 top: 1,
  28.                 width: 100,
  29.                 height: 100
  30.             };
  31.         }
  32.     }, {
  33.         getBoundingClientRect() {
  34.             return {
  35.                 bottom: -1,
  36.                 left: -1,
  37.                 right: -1,
  38.                 top: -1,
  39.                 width: 100,
  40.                 height: 100
  41.             };
  42.         }
  43.     }], opts);
  44.  
  45.     t.true(!registry.current.length);
  46.  
  47.     registry.check();
  48.     t.true(registry.current.length === 1);
  49.  
  50. });
  51.  
  52. test('Registry.check emits enter events', t => {
  53.  
  54.     let stub = {
  55.         getBoundingClientRect() {
  56.             return {
  57.                 bottom: 1,
  58.                 left: 1,
  59.                 right: 1,
  60.                 top: 1,
  61.                 width: 100,
  62.                 height: 100
  63.             };
  64.         }
  65.     };
  66.  
  67.     let registry = Registry([stub], opts);
  68.  
  69.     registry.on('enter', el => t.deepEqual(el, stub));
  70.     registry.check();
  71.  
  72. });
  73.  
  74. test('Registry.check emits exit events', t => {
  75.  
  76.     let stub = {
  77.         getBoundingClientRect() {
  78.             return {
  79.                 bottom: -1,
  80.                 left: -1,
  81.                 right: -1,
  82.                 top: -1,
  83.                 width: 100,
  84.                 height: 100
  85.             };
  86.         }
  87.     };
  88.  
  89.     let registry = Registry([stub], opts);
  90.  
  91.     registry.on('exit', el => t.deepEqual(el, stub));
  92.     registry.check();
  93.  
  94. });
  95.  
  96. test('Registry.check returns the registry', t => {
  97.     let registry = Registry([], opts);
  98.     t.deepEqual(registry.check(), registry);
  99. });
  100.  
downloadregistry.check.spec.js Source code - Download in-view Source code
Related Source Codes/Software:
magictools - 2017-01-09
elm-compiler - Compiler for Elm, a functional language for reliab... 2017-01-09
Twig - Twig, the flexible, fast, and secure template lang... 2017-01-09
android-testing - A collection of samples demonstrating different fr... 2017-01-09
lib-flexible - Scalable layout scheme 2017-01-09
sinon - Test spies, stubs and mocks for JavaScript. ... 2017-01-09
docker-gitlab - Dockerized GitLab http://www.da... 2017-01-09
Side-Menu.Android - Side menu with some categories to choose. ... 2017-01-09
libsodium - A modern and easy-to-use crypto library. 2017-01-09
prerender - Node server that uses phantomjs to render a javasc... 2017-01-09
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top