本文整理匯總了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);
});