本文整理汇总了TypeScript中@cycle/dom.mockDOMSource函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mockDOMSource函数的具体用法?TypeScript mockDOMSource怎么用?TypeScript mockDOMSource使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mockDOMSource函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: mockSources
function mockSources(selector, id, name) {
return Object.assign({},
{DOM: mockDOMSource(RxAdapter, {
selector: {'click': O.of({target: {innerHTML: '5'}})}})},
{props$: O.of({id, name})}
);
}
示例2: test
test({type: 'DELETE ITEM', payload: 11}, function() {
const DOM = mockDOMSource(RxJSAdapter, {});
const mockBLaction$ = O.of({type: 'DELETE', payload: 11});
expect(intent(DOM, mockBLaction$).isEmpty())
.toBeStreamOf(false);
expect(intent(DOM, mockBLaction$).last())
.toBeStreamOf({type: 'DELETE ITEM', payload: 11});
});
示例3: test
test('DOM flows to intent', function() {
const DOM = mockDOMSource(RxJSAdapter, {
'.rollButton': {
'click': O.of({target: {innerHTML: '5'}})
}
});
BowlingLine({DOM}, nullView, nullModel, intent);
function intent(DOMSource) {
const rollButton$ = DOMSource.select('.rollButton').events('click');
expect(rollButton$.map(evt => evt.target.innerHTML)).toBeStreamOf('5');
return O.of({type: 'ROLL', payload: 5});
}
});
示例4: test
test('intent is function from DOMSource to observable of actions', function() {
const DOM = mockDOMSource(RxJSAdapter, {
'.foo': {
'click': O.of({target: {innerHTML: '123'}})
}
});
Component({DOM}, nullModel, nullView, intent);
function intent(DOMSource, ...rest) {
const rollButton$ = DOMSource.select('.foo').events('click');
expect(rollButton$.map(evt => evt.target.innerHTML)).toBeStreamOf('123');
return O.empty();
}
});
示例5: test
test('confirm actions from DOM', function() {
[
[mockDOMSource(
RxAdapter, {'.rollButton': {'click': O.of({target: {innerHTML: '5'}})}}
), {type: 'ROLL', payload: 5}],
[mockDOMSource(
RxAdapter, {'.newGame': {'click': O.of({})}}
), {type: 'NEW GAME'}],
[mockDOMSource(
RxAdapter, {'.undo': {'click': O.of({})}}
), {type: 'UNDO'}],
[mockDOMSource(
RxAdapter, {'.redo': {'click': O.of({})}}
), {type: 'REDO'}],
[mockDOMSource(
RxAdapter, {'.delete': {'click': O.of({})}}
), {type: 'DELETE'}]
].forEach(([DOMSource, action]) =>
test(action, function() {
expect(intent(DOMSource).isEmpty()).toBeStreamOf(false);
expect(intent(DOMSource)).toBeStreamOf(action);
})
);
});
示例6: it
it('can be used to test Cycle apps', done => {
function Counter({DOM}: any) {
const add$ = DOM.select('.add')
.events('click')
.mapTo(+1);
const subtract$ = DOM.select('.subtract')
.events('click')
.mapTo(-1);
const change$ = xs.merge(add$, subtract$);
const add = (a: number, b: number) => a + b;
const count$ = change$.fold(add, 0);
return {
count$,
};
}
const Time = mockTimeSource();
const addClick = '---x-x-x------x-|';
const subtractClick = '-----------x----|';
const expectedCount = '0--1-2-3---2--3-|';
const _DOM = mockDOMSource({
'.add': {
click: Time.diagram(addClick),
},
'.subtract': {
click: Time.diagram(subtractClick),
},
});
const counter = Counter({DOM: _DOM});
Time.assertEqual(counter.count$, Time.diagram(expectedCount));
Time.run(done);
});
示例7: withTime
withTime(Time => {
const add$ = Time.diagram(addDiagram)
const subtract$ = Time.diagram(subtractDiagram)
const DOM = mockDOMSource({
'.add': { click: add$ },
'.subtract': { click: subtract$ }
})
const app = onionify(App)({ DOM } as any)
const html$ = (app.DOM as Stream<VNode>).map(toHtml)
const expected$ = xs
.merge(add$.mapTo(+1), subtract$.mapTo(-1))
.fold((acc, curr) => acc + curr, 0)
.map(expectedHTML)
Time.assertEqual(html$, expected$, htmlLooksLike)
})
示例8: forall
const property = forall(diagramArbitrary, diagramArbitrary, (addDiagram, subtractDiagram) => {
const Time = mockTimeSource();
const add$ = Time.diagram(addDiagram);
const subtract$ = Time.diagram(subtractDiagram);
const DOM = mockDOMSource({
'.add': { click: add$ },
'.subtract': { click: subtract$ }
});
const app = onionify(App)({ DOM } as any);
const html$ = app.DOM.map(toHtml);
const expected$ = xs.merge(add$.mapTo(+1), subtract$.mapTo(-1))
.fold((acc, curr) => acc + curr, 0)
.map(expectedHTML);
Time.assertEqual(html$, expected$, htmlLooksLike);
return promise(Time.run);
});