it('should throw if passed invalid store shape', () => {
      let result = false;

      Reflect.deleteProperty(store, 'dispatch');

      try {
        getAsyncInjectors(store);
      } catch (err) {
        result = err.name === 'Invariant Violation';
      }

      expect(result).toEqual(true);
    });
		it('does not append trailing separator when directory', function (done) {
			var file = new File({
				path: '/test/foo',
				stat: {
					isDirectory: function () {
						return true;
					},
				} as any as fs.Stats,
			});

			expect(file.basename).toEqual('foo');
			done();
		});
		it('removes trailing separator when symlink', function (done) {
			var file = new File({
				path: '/test/foo/',
				stat: {
					isSymbolicLink: function () {
						return true;
					},
				} as any as fs.Stats,
			});

			expect(file.basename).toEqual('foo');
			done();
		});
Example #4
0
  it('resets the points of players', () => {
    const initialState = new State()
      .setIn(['players', 1], new Player({
        points: 10,
      }));

    const state = reducer(initialState, {
      type: 'startMatch',
      endTime: 123,
    });

    expect(state.players.get(1).points).toEqual(0);
  });
  it('should override old image when ATTACH_IMAGE', () => {
    const imageLink = 'http://whatever';
    const newerImageLink = 'http://igiveashit';
    const nodeId = this.leaf.data.id;

    const action = graphManipulationActions.attachImageToNode(imageLink, this.leaf);
    const newState = graphReducer(this.mockState, action);
    const nextAction = graphManipulationActions.attachImageToNode(newerImageLink, this.leaf);
    const newerState = graphReducer(newState, nextAction);

    const nodeWithImage = findNode(newerState.raw, nodeId).node;
    expect(nodeWithImage.image).toEqual(newerImageLink);
  });
Example #6
0
      Render.into(document.body, init, () => {
        const [span, div, text] = Array.from(document.body.childNodes)

        expect((span as HTMLElement).tagName).toBe('SPAN')
        expect((div as HTMLElement).tagName).toBe('DIV')
        expect(text).toExist()
        expect(text.textContent).toBe('some text')

        const updated = [
          h('span'),
          h('input'),
          'some text (2)'
        ]

        // Update 1: Swap the middle element
        Render.into(init, updated, () => {
          const [updatedSpan, input, updatedText] = Array.from(document.body.childNodes)

          expect(updatedSpan).toBe(span)
          expect((input as HTMLElement).tagName).toBe('INPUT')
          expect(updatedText).toBe(text)
          expect(updatedText.textContent).toBe('some text (2)')

          const emptyNodes: VNode[] = []

          // Update 2: Empty array
          Render.into(updated, emptyNodes, () => {
            expect(document.body.children.length).toBe(0)

            // Update 3: Go back to the second VNode structure
            Render.into(emptyNodes, updated, () => {
              expect(document.body.childNodes.length).toBe(3)
              done()
            })
          })

        })
      })
Example #7
0
 it('should render 2-level template with children and props', () => {
   expect(render({
     tagName: 'div',
     children: {
       tagName: 'div',
       children: 'Hello',
       props: {
         'data-title': 'Greeting',
       },
     },
   })).toBe(
     '<div><div data-title="Greeting">Hello</div></div>'
   );
 });
Example #8
0
 it('should render 2-level template with array of children', () => {
   expect(render({
     tagName: 'div',
     children: [{
       tagName: 'div',
       children: 'Children 1',
     }, {
       tagName: 'div',
       children: 'Children 2',
     }],
   })).toBe(
     '<div><div>Children 1</div><div>Children 2</div></div>'
   );
 });
Example #9
0
		it('copies history', function (done) {
			var options = {
				cwd: '/',
				base: '/test/',
				path: '/test/test.coffee',
				contents: null,
			};
			var history = [
				path.normalize('/test/test.coffee'),
				path.normalize('/test/test.js'),
				path.normalize('/test/test-938di2s.js'),
			];

			var file = new File(options);
			file.path = history[1];
			file.path = history[2];
			var file2 = file.clone();

			expect(file2.history).toEqual(history);
			expect(file2.history).toNotBe(file.history);
			expect(file2.path).toEqual(history[2]);
			done();
		});
Example #10
0
		it('does not append separator when symlink', function (done) {
			var file = new File({
				base: '/test',
				path: '/test/foo/bar',
				stat: {
					isSymbolicLink: function () {
						return true;
					},
				} as any as fs.Stats,
			});

			expect(file.relative).toEqual(path.normalize('foo/bar'));
			done();
		});
Example #11
0
		it('records path in history when set', function (done) {
			var val = path.normalize('/test/test.js');
			var file = new File({
				cwd: '/',
				path: '/test/test.coffee',
			});
			var history = [
				path.normalize('/test/test.coffee'),
				val,
			];

			file.path = val;
			expect(file.path).toEqual(val);
			expect(file.history).toEqual(history);

			var val2 = path.normalize('/test/test.es6');
			history.push(val2);

			file.path = val2;
			expect(file.path).toEqual(val2);
			expect(file.history).toEqual(history);
			done();
		});
Example #12
0
		it('does not append separator when directory', done => {
			const file = new File({
				base: '/test',
				path: '/test/foo/bar',
				stat: {
					isDirectory() {
						return true;
					},
				} as any as fs.Stats,
			});

			expect(file.relative).toEqual(path.normalize('foo/bar'));
			done();
		});
Example #13
0
  it('can render with a custom selector', () => {

    const table = (() => {
      function initState() { return {} }
      function connect() {}

      function render() {
        return h('button')
      }

      return function() {
        return Component({ sel: 'table.large', name: 'table', initState, connect, render })
      }
    })()

    expect(table().sel).toBe('table.large')

    startApp({ app: table(), elm: document.body, snabbdomModules })

    expect(document.body.firstElementChild!.tagName).toBe('TABLE')
    expect(document.body.firstElementChild!.className).toBe('large')
    expect(document.body.firstElementChild!.firstElementChild!.tagName).toBe('BUTTON')
  })
Example #14
0
  it('can abort message infinite loops and notify us about it', () => {

    let pingCount = 0

    const ping = Message('ping')
    const pong = Message('pong')

    const store = Store({}, ({on, state}) => {
      on(ping, () => {
        pingCount++
        store.send(pong())
      })
      on(pong, () => store.send(ping()))
    })

    function sendPing() {
      store.send(ping())
    }

    expect(sendPing).toThrow()

    // Some cycles are allowed
    expect(pingCount).toBe(5)
  })
Example #15
0
  it('does not award points to players who failed to score', () => {
    let players = I.Map<number, Player>();

    players = players
      .set(1, new Player({
        id: 1,
        scored: false,
        strokes: 3,
        scoreTime: 1,
      }))
      .set(2, new Player({
        id: 2,
        scored: true,
        strokes: 4,
        scoreTime: 1,
        points: 5,
      }));

    const ranked = rankPlayers(players);
    players = updatePoints(players, ranked);

    expect(players.get(1).points).toEqual(0);
    expect(players.get(2).points).toEqual(25);
  });
Example #16
0
  it('sets top 25% and top 50% scores', () => {
    let {players, ranked} = generateRankedPlayers(20);
    players = updatePoints(players, ranked);

    const points = players.map((player) => player.points).toList();

    expect(points.toJS()).toEqual([
      20,
      15,
      12,
      10,
      10,
      5, 5, 5, 5, 5,
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    ]);
  });
Example #17
0
		it('removes trailing separator when directory & symlink', done => {
			const file = new File({
				path: '/test/foo/',
				stat: {
					isDirectory() {
						return true;
					},
					isSymbolicLink() {
						return true;
					},
				} as any as fs.Stats,
			});

			expect(file.basename).toEqual('foo');
			done();
		});
Example #18
0
  it('ranks players by strokes', () => {
    const players = I.Map<number, Player>()
      .set(1, new Player({
        id: 1,
        scored: true,
        strokes: 3,
        scoreTime: 1000,
      }))
      .set(2, new Player({
        id: 2,
        scored: true,
        strokes: 2,
        scoreTime: 1000,
      }));

    const ranked = rankPlayers(players);

    expect(ranked.get(0)).toEqual(2);
  });
      it('should throw if passed invalid reducer', () => {
        let result = false;

        const injectReducer = injectAsyncReducer(store);

        try {
          injectReducer('bad', 'nope');
        } catch (err) {
          result = err.name === 'Invariant Violation';
        }

        try {
          injectReducer('coolio', 12345);
        } catch (err) {
          result = err.name === 'Invariant Violation';
        }

        expect(result).toEqual(true);
      });
      it('should throw if passed invalid saga', () => {
        let result = false;

        const injectSagas = injectAsyncSagas(store);

        try {
          injectSagas({ testSaga });
        } catch (err) {
          result = err.name === 'Invariant Violation';
        }

        try {
          injectSagas(testSaga);
        } catch (err) {
          result = err.name === 'Invariant Violation';
        }

        expect(result).toEqual(true);
      });
      it('should throw if passed invalid name', () => {
        let result = false;

        const injectReducer = injectAsyncReducer(store);

        try {
          injectReducer('', reducer);
        } catch (err) {
          result = err.name === 'Invariant Violation';
        }

        try {
          injectReducer(999, reducer);
        } catch (err) {
          result = err.name === 'Invariant Violation';
        }

        expect(result).toEqual(true);
      });
    it(`executes with success`, () => {
      const prefix = "a"
      const fetchIterator = searchWorker(searchStart(prefix))
      let result: IteratorResult<CallEffect | PutEffect<any>>

      result = fetchIterator.next()
      expect(result.value).toEqual(call(delay, 200))
      expect(result.done).toBe(false)

      result = fetchIterator.next()
      expect(result.value).toEqual(call(search, prefix))
      expect(result.done).toBe(false)

      result = fetchIterator.next()
      expect(result.value).toEqual(put(searchDone()))
      expect(result.done).toBe(false)

      result = fetchIterator.next()
      expect(result.done).toBe(true)
    })
Example #23
0
		it('copies custom properties', function (done) {
			var options = {
				cwd: '/',
				base: '/test/',
				path: '/test/test.coffee',
				contents: null,
				custom: { meta: {} },
			};

			var file = new File(options) as TestFile;
			var file2 = file.clone();

			expect(file2).toNotBe(file);
			expect(file2.cwd).toEqual(file.cwd);
			expect(file2.base).toEqual(file.base);
			expect(file2.path).toEqual(file.path);
			expect(file2.custom).toNotBe(file.custom);
			expect(file2.custom.meta).toNotBe(file.custom.meta);
			expect(file2.custom).toEqual(file.custom);
			done();
		});
Example #24
0
		it('copies all attributes over with Buffer contents', function (done) {
			var options = {
				cwd: '/',
				base: '/test/',
				path: '/test/test.coffee',
				contents: new Buffer('test'),
			};
			var file = new File(options);
			var file2 = file.clone();

			expect(file2).toNotBe(file);
			expect(file2.cwd).toEqual(file.cwd);
			expect(file2.base).toEqual(file.base);
			expect(file2.path).toEqual(file.path);
			expect(file2.contents).toNotBe(file.contents);
			expect(file2.contents.toString('utf8')).toEqual(file.contents.toString('utf8'));
			done();
		});
Example #25
0
  it('supports messages sent from within message handlers with properly update state in between', () => {

    const increaseBy = Message<number>('increaseBy')
    const pleaseIncreaseBy = Message<number>('pleaseIncreaseBy')

    const initState = { num: 10 }

    const store = Store(initState, ({on, msg, state}) => {
      on(pleaseIncreaseBy, by => {
        store.send(increaseBy(by))
        return { num: state().num * 2 }
      })

      on(increaseBy, by => {
        // If was first updated by the pleaseIncreaseBy
        expect(state().num).toBe(20)

        return { num: state().num + by }
      })
    })

    store.send(pleaseIncreaseBy(5))
    expect(store.state()).toEqual({ num: 25 })
  })
Example #26
0
    requestAnimationFrame(() => {
      // The component node is stable
      const newComp = document.body.firstElementChild
      expect(newComp).toBe(comp)

      // Test the patching occurs properly
      expect(comp.children[0].tagName).toBe('BUTTON')
      expect(comp.children[1].tagName).toBe('P')
      expect(comp.children[2].tagName).toBe('SPAN')

      // No reason for these to have changed reference
      expect(comp.children[0]).toBe(buttonEl)
      expect(comp.children[2]).toBe(spanEl)

      // Destroy the component
      Render.into(app, h('div'), () => {
        expect(document.body.firstElementChild!.tagName).toBe('DIV')
        expect(destroyCalled).toBe(true)
        done()
      })
    })
 it('should contain a hook for `sagaMiddleware.run`', () => {
   expect(typeof store.runSaga).toEqual('function');
 });
Example #28
0
 .expect((res) => {
     expect(res.body.message).toBe("Vote Registered")
 })
 it('should contain an object for async reducers', () => {
   expect(typeof store.asyncReducers).toEqual('object');
 });
Example #30
0
 .expect((res) => {
     expect(res.body.message).toBe("No Person Specified")
 })