@enact/core
Advanced tools
Comparing version 2.2.9 to 2.3.0-alpha.1
@@ -5,2 +5,12 @@ # Change Log | ||
## [2.3.0] - 2019-02-11 | ||
### Deprecated | ||
- `core/kind` config property `contextTypes`, to be removed in 3.0. | ||
### Added | ||
- `core/kind` config property `contextType` replacing legacy `contextTypes` property | ||
## [2.2.9] - 2019-01-11 | ||
@@ -7,0 +17,0 @@ |
"use strict"; | ||
var _sinon = _interopRequireDefault(require("sinon")); | ||
var _consoleSnoop = require("console-snoop"); | ||
var _dispatcher = require("../dispatcher"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* global CustomEvent */ | ||
describe('dispatcher', function () { | ||
it('should register handlers on target', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should register handlers on target', function () { | ||
var handler = jest.fn(); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
var ev = new window.CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not register duplicate handlers on target', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should not register duplicate handlers on target', function () { | ||
var handler = jest.fn(); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
var ev = new window.CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should unregister handlers on target', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should unregister handlers on target', function () { | ||
var handler = jest.fn(); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
var ev = new window.CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
(0, _dispatcher.off)('localechange', handler, window); | ||
window.dispatchEvent(ev); | ||
var expected = false; | ||
var actual = handler.calledTwice; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should only call a "once" handler once', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should only call a "once" handler once', function () { | ||
var handler = jest.fn(); | ||
(0, _dispatcher.once)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
var ev = new window.CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
window.dispatchEvent(ev); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should allow unregistering a "once" before it is called', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should allow unregistering a "once" before it is called', function () { | ||
var handler = jest.fn(); | ||
var onceHandler = (0, _dispatcher.once)('localechange', handler, window); | ||
(0, _dispatcher.off)('localechange', onceHandler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
var ev = new window.CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = false; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 0; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not block subsequent handlers when a handler throws', function () { | ||
// clear enyo-console-spy so we can stub it to suppress the console.error | ||
(0, _consoleSnoop.restoreErrorAndWarnings)(); | ||
test('should not block subsequent handlers when a handler throws', function () { | ||
// Modify the console spy to silence error output with | ||
// an empty mock implementation | ||
// eslint-disable-next-line no-console | ||
console.error.mockImplementation(); | ||
_sinon.default.stub(console, 'error'); | ||
var throws = function throws() { | ||
@@ -78,16 +66,11 @@ throw new Error('Thrown from handler'); | ||
var handler = _sinon.default.spy(); | ||
var handler = jest.fn(); | ||
(0, _dispatcher.on)('localechange', throws, window); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); // restore console.error and set up enyo-console-spy again so it can complete successfully | ||
// eslint-disable-next-line no-console | ||
console.error.restore(); | ||
(0, _consoleSnoop.watchErrorAndWarnings)(); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var ev = new window.CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
}); |
"use strict"; | ||
var _sinon = _interopRequireDefault(require("sinon")); | ||
var _handle = require("../handle"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
@@ -16,4 +12,4 @@ | ||
return _objectSpread({ | ||
preventDefault: _sinon.default.spy(), | ||
stopPropagation: _sinon.default.spy() | ||
preventDefault: jest.fn(), | ||
stopPropagation: jest.fn() | ||
}, payload); | ||
@@ -30,105 +26,94 @@ }; | ||
it('should call only handler', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
test('should call only handler', function () { | ||
var handler = jest.fn(returnsTrue); | ||
var callback = (0, _handle.handle)(handler); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should call multiple handlers', function () { | ||
var handler1 = _sinon.default.spy(returnsTrue); | ||
var handler2 = _sinon.default.spy(returnsTrue); | ||
test('should call multiple handlers', function () { | ||
var handler1 = jest.fn(returnsTrue); | ||
var handler2 = jest.fn(returnsTrue); | ||
var callback = (0, _handle.handle)(handler1, handler2); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = handler1.calledOnce && handler2.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var actual = handler1.mock.calls.length === 1 && handler2.mock.calls.length === 1; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should skip non-function handlers', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
test('should skip non-function handlers', function () { | ||
var handler = jest.fn(returnsTrue); | ||
var callback = (0, _handle.handle)(null, void 0, 0, 'purple', handler); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not call handlers after one that returns false', function () { | ||
var handler1 = _sinon.default.spy(returnsTrue); | ||
var handler2 = _sinon.default.spy(returnsTrue); | ||
test('should not call handlers after one that returns false', function () { | ||
var handler1 = jest.fn(returnsTrue); | ||
var handler2 = jest.fn(returnsTrue); | ||
var callback = (0, _handle.handle)(handler1, returnsFalse, handler2); | ||
callback(makeEvent()); | ||
var expected = false; | ||
var actual = handler2.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 0; | ||
var actual = handler2.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should call stopPropagation on event', function () { | ||
test('should call stopPropagation on event', function () { | ||
var callback = (0, _handle.handle)(_handle.stop); | ||
var ev = makeEvent(); | ||
callback(ev); | ||
var expected = true; | ||
var actual = ev.stopPropagation.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = ev.stopPropagation.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should call preventDefault on event', function () { | ||
test('should call preventDefault on event', function () { | ||
var callback = (0, _handle.handle)(_handle.preventDefault); | ||
var ev = makeEvent(); | ||
callback(ev); | ||
var expected = true; | ||
var actual = ev.preventDefault.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = ev.preventDefault.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should call any method on event', function () { | ||
test('should call any method on event', function () { | ||
var callback = (0, _handle.handle)((0, _handle.callOnEvent)('customMethod')); | ||
var ev = makeEvent({ | ||
customMethod: _sinon.default.spy() | ||
customMethod: jest.fn() | ||
}); | ||
callback(ev); | ||
var expected = true; | ||
var actual = ev.customMethod.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = ev.customMethod.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should only call handler for specified keyCode', function () { | ||
test('should only call handler for specified keyCode', function () { | ||
var keyCode = 13; | ||
var handler = _sinon.default.spy(); | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.handle)((0, _handle.forKeyCode)(keyCode), handler); | ||
callback(makeEvent()); | ||
expect(handler.calledOnce).to.equal(false); | ||
expect(handler).not.toHaveBeenCalled(); | ||
callback(makeEvent({ | ||
keyCode: keyCode | ||
})); | ||
expect(handler.calledOnce).to.equal(true); | ||
expect(handler).toHaveBeenCalled(); | ||
}); | ||
it('should only call handler for specified event prop', function () { | ||
test('should only call handler for specified event prop', function () { | ||
var prop = 'index'; | ||
var value = 0; | ||
var handler = _sinon.default.spy(); | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.handle)((0, _handle.forEventProp)(prop, value), handler); // undefined shouldn't pass | ||
callback(makeEvent()); | ||
expect(handler.calledOnce).to.equal(false); // == check shouldn't pass | ||
expect(handler).not.toHaveBeenCalled(); // == check shouldn't pass | ||
callback(makeEvent(_defineProperty({}, prop, false))); | ||
expect(handler.calledOnce).to.equal(false); // === should pass | ||
expect(handler).not.toHaveBeenCalled(); // === should pass | ||
callback(makeEvent(_defineProperty({}, prop, value))); | ||
expect(handler.calledOnce).to.equal(true); | ||
expect(handler).toHaveBeenCalled(); | ||
}); | ||
it('should only call handler for specified prop', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should only call handler for specified prop', function () { | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.handle)((0, _handle.forProp)('checked', true), handler); // undefined shouldn't pass | ||
callback({}, {}); | ||
expect(handler.calledOnce).to.equal(false); // == check shouldn't pass | ||
expect(handler).not.toHaveBeenCalled(); // == check shouldn't pass | ||
@@ -138,3 +123,3 @@ callback({}, { | ||
}); | ||
expect(handler.calledOnce).to.equal(false); // === should pass | ||
expect(handler).not.toHaveBeenCalled(); // === should pass | ||
@@ -144,11 +129,10 @@ callback({}, { | ||
}); | ||
expect(handler.calledOnce).to.equal(true); | ||
expect(handler).toHaveBeenCalled(); | ||
}); | ||
it('should forward events to function specified in provided props', function () { | ||
test('should forward events to function specified in provided props', function () { | ||
var event = 'onMyClick'; | ||
var prop = 'index'; | ||
var propValue = 0; | ||
var spy = jest.fn(); | ||
var spy = _sinon.default.spy(); | ||
var props = _defineProperty({}, event, spy); | ||
@@ -160,19 +144,15 @@ | ||
var expected = true; | ||
var actual = spy.args[0][0][prop] === propValue; | ||
expect(actual).to.equal(expected); | ||
var actual = spy.mock.calls[0][0][prop] === propValue; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should forwardWithPrevent events to function specified in provided props when preventDefault() hasn\'t been called', function () { | ||
test('should forwardWithPrevent events to function specified in provided props when preventDefault() hasn\'t been called', function () { | ||
var event = 'onMyClick'; | ||
var handler = _sinon.default.spy(); | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler); | ||
callback(); | ||
expect(handler.calledOnce).to.equal(true); | ||
expect(handler).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should not forwardWithPrevent events to function specified in provided props when preventDefault() has been called', function () { | ||
test('should not forwardWithPrevent events to function specified in provided props when preventDefault() has been called', function () { | ||
var event = 'onMyClick'; | ||
var handler = _sinon.default.spy(); | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler); // should stop chain when `preventDefault()` has been called | ||
@@ -185,5 +165,5 @@ | ||
}); | ||
expect(handler.calledOnce).to.equal(false); | ||
expect(handler).not.toHaveBeenCalled(); | ||
}); | ||
it('should include object props as second arg when bound', function () { | ||
test('should include object props as second arg when bound', function () { | ||
var componentInstance = { | ||
@@ -195,5 +175,4 @@ context: {}, | ||
}; | ||
var handler = jest.fn(); | ||
var handler = _sinon.default.spy(); | ||
var h = _handle.handle.bind(componentInstance); | ||
@@ -204,6 +183,6 @@ | ||
var expected = 1; | ||
var actual = handler.firstCall.args[1].value; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls[0][1].value; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should include object context as third arg when bound', function () { | ||
test('should include object context as third arg when bound', function () { | ||
var componentInstance = { | ||
@@ -215,5 +194,4 @@ context: { | ||
}; | ||
var handler = jest.fn(); | ||
var handler = _sinon.default.spy(); | ||
var h = _handle.handle.bind(componentInstance); | ||
@@ -224,27 +202,24 @@ | ||
var expected = 1; | ||
var actual = handler.firstCall.args[2].value; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls[0][2].value; | ||
expect(actual).toBe(expected); | ||
}); | ||
describe('finally', function () { | ||
it('should call the finally callback when handle returns true', function () { | ||
var finallyCallback = _sinon.default.spy(); | ||
test('should call the finally callback when handle returns true', function () { | ||
var finallyCallback = jest.fn(); | ||
var callback = (0, _handle.handle)(returnsTrue).finally(finallyCallback); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = finallyCallback.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = finallyCallback.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should call the finally callback when handle returns false', function () { | ||
var finallyCallback = _sinon.default.spy(); | ||
test('should call the finally callback when handle returns false', function () { | ||
var finallyCallback = jest.fn(); | ||
var callback = (0, _handle.handle)(returnsFalse).finally(finallyCallback); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = finallyCallback.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = finallyCallback.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should call the finally callback when handle throws an error', function () { | ||
var finallyCallback = _sinon.default.spy(); | ||
test('should call the finally callback when handle throws an error', function () { | ||
var finallyCallback = jest.fn(); | ||
var callback = (0, _handle.handle)(function () { | ||
@@ -259,11 +234,10 @@ throw new Error('Something has gone awry ...'); | ||
var expected = true; | ||
var actual = finallyCallback.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = finallyCallback.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
describe('#oneOf', function () { | ||
it('should call each handler until one passes', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
test('should call each handler until one passes', function () { | ||
var handler = jest.fn(returnsTrue); | ||
var h1 = [returnsFalse, handler]; | ||
@@ -274,17 +248,15 @@ var h2 = [returnsTrue, handler]; | ||
var expected = 1; | ||
var actual = handler.callCount; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should stop if the first handler passes', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
test('should stop if the first handler passes', function () { | ||
var handler = jest.fn(returnsTrue); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler], [returnsTrue, handler], [returnsTrue, handler]); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.callCount; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should pass args to condition', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
test('should pass args to condition', function () { | ||
var handler = jest.fn(returnsTrue); | ||
var callback = (0, _handle.oneOf)([handler, returnsTrue]); | ||
@@ -296,8 +268,7 @@ var ev = { | ||
var expected = ev; | ||
var actual = handler.firstCall.args[0]; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls[0][0]; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should pass args to handlers', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
test('should pass args to handlers', function () { | ||
var handler = jest.fn(returnsTrue); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler]); | ||
@@ -309,6 +280,6 @@ var ev = { | ||
var expected = ev; | ||
var actual = handler.firstCall.args[0]; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls[0][0]; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should return true when the passed condition branch returns a truthy value', function () { | ||
test('should return true when the passed condition branch returns a truthy value', function () { | ||
var callback = (0, _handle.oneOf)([returnsTrue, function () { | ||
@@ -319,5 +290,5 @@ return 'ok'; | ||
var actual = callback(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should return false when the passed condition branch returns a falsy value', function () { | ||
test('should return false when the passed condition branch returns a falsy value', function () { | ||
var callback = (0, _handle.oneOf)([returnsTrue, function () { | ||
@@ -328,11 +299,11 @@ return null; | ||
var actual = callback(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should return false when no conditions pass', function () { | ||
test('should return false when no conditions pass', function () { | ||
var callback = (0, _handle.oneOf)([returnsFalse, returnsTrue], [returnsFalse, returnsTrue]); | ||
var expected = false; | ||
var actual = callback(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support bound handlers', function () { | ||
test('should support bound handlers', function () { | ||
var componentInstance = { | ||
@@ -344,5 +315,4 @@ props: {}, | ||
}; | ||
var handler = jest.fn(); | ||
var handler = _sinon.default.spy(); | ||
var h = _handle.handle.bind(componentInstance); | ||
@@ -353,6 +323,6 @@ | ||
var expected = 1; | ||
var actual = handler.firstCall.args[2].value; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls[0][2].value; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should include object props as second arg when bound', function () { | ||
test('should include object props as second arg when bound', function () { | ||
var componentInstance = { | ||
@@ -364,5 +334,4 @@ props: { | ||
}; | ||
var handler = jest.fn(); | ||
var handler = _sinon.default.spy(); | ||
var o = _handle.oneOf.bind(componentInstance); | ||
@@ -373,6 +342,6 @@ | ||
var expected = 1; | ||
var actual = handler.firstCall.args[1].value; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls[0][1].value; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should include object context as third arg when bound', function () { | ||
test('should include object context as third arg when bound', function () { | ||
var componentInstance = { | ||
@@ -384,5 +353,4 @@ props: {}, | ||
}; | ||
var handler = jest.fn(); | ||
var handler = _sinon.default.spy(); | ||
var o = _handle.oneOf.bind(componentInstance); | ||
@@ -393,18 +361,17 @@ | ||
var expected = 1; | ||
var actual = handler.firstCall.args[2].value; | ||
expect(actual).to.equal(expected); | ||
var actual = handler.mock.calls[0][2].value; | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support finally callback', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should support finally callback', function () { | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.oneOf)([returnsFalse, returnsTrue], [returnsFalse, returnsTrue]).finally(handler); | ||
callback(); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
var expected = 1; | ||
var actual = handler.mock.calls.length; | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
describe('#adaptEvent', function () { | ||
it('should pass the adapted event payload to the provided handler', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should pass the adapted event payload to the provided handler', function () { | ||
var handler = jest.fn(); | ||
@@ -426,7 +393,7 @@ var onlyValue = function onlyValue(_ref) { | ||
}; | ||
var actual = handler.firstCall.args[0]; | ||
expect(actual).to.deep.equal(expected); | ||
var actual = handler.mock.calls[0][0]; | ||
expect(actual).toEqual(expected); | ||
}); | ||
it('should pass additional arguments to the provided handler', function () { | ||
var handler = _sinon.default.spy(); | ||
test('should pass additional arguments to the provided handler', function () { | ||
var handler = jest.fn(); | ||
@@ -439,6 +406,6 @@ var returnOne = function returnOne() { | ||
var expected = [1, 2, 3]; | ||
var actual = handler.firstCall.args; | ||
expect(actual).to.deep.equal(expected); | ||
var actual = handler.mock.calls[0]; | ||
expect(actual).toEqual(expected); | ||
}); | ||
it('should support bound adapter function', function () { | ||
test('should support bound adapter function', function () { | ||
var obj = { | ||
@@ -449,14 +416,12 @@ adapt: function adapt() { | ||
}; | ||
var handler = _sinon.default.spy(); | ||
var handler = jest.fn(); | ||
var fn = (0, _handle.adaptEvent)((0, _handle.call)('adapt'), handler).bind(obj); | ||
fn(0, 2, 3); | ||
var expected = [1, 2, 3]; | ||
var actual = handler.firstCall.args; | ||
expect(actual).to.deep.equal(expected); | ||
var actual = handler.mock.calls[0]; | ||
expect(actual).toEqual(expected); | ||
}); | ||
it('should support bound handler function', function () { | ||
test('should support bound handler function', function () { | ||
var obj = { | ||
handler: _sinon.default.spy() | ||
handler: jest.fn() | ||
}; | ||
@@ -471,6 +436,6 @@ | ||
var expected = [1, 2, 3]; | ||
var actual = obj.handler.firstCall.args; | ||
expect(actual).to.deep.equal(expected); | ||
var actual = obj.handler.mock.calls[0]; | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); |
@@ -27,3 +27,3 @@ "use strict"; | ||
}); | ||
it('should support HoC factory function as first argument to hoc()', function () { | ||
test('should support HoC factory function as first argument to hoc()', function () { | ||
var ImplicitNullHoC = (0, _hoc.default)(function (config, Wrapped) { | ||
@@ -38,5 +38,5 @@ return function () { | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support DOM node name as first argument to HoC', function () { | ||
test('should support DOM node name as first argument to HoC', function () { | ||
var Component = HoC('span'); | ||
@@ -46,5 +46,5 @@ var subject = (0, _enzyme.shallow)(_react.default.createElement(Component, null)); | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support React component as first argument to HoC', function () { | ||
test('should support React component as first argument to HoC', function () { | ||
function Thing() { | ||
@@ -58,5 +58,5 @@ return _react.default.createElement("div", null); | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should use default config when instance config is omitted', function () { | ||
test('should use default config when instance config is omitted', function () { | ||
var Component = HoC('span'); | ||
@@ -66,5 +66,5 @@ var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var actual = subject.find('span').prop('color'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should overwrite default config with instance config', function () { | ||
test('should overwrite default config with instance config', function () { | ||
var instanceConfig = { | ||
@@ -77,5 +77,5 @@ color: 'green' | ||
var actual = subject.find('div').prop('color'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should allow construction without default or instance configs', function () { | ||
test('should allow construction without default or instance configs', function () { | ||
var Component = NullHoC('div'); | ||
@@ -85,5 +85,5 @@ var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var actual = subject.find('div').length; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should allow construction without default config', function () { | ||
test('should allow construction without default config', function () { | ||
var instanceConfig = { | ||
@@ -96,4 +96,4 @@ color: 'green' | ||
var actual = subject.find('div').prop('color'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
}); |
@@ -32,33 +32,18 @@ "use strict"; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
// Invokes `name` on `provider` with `args` | ||
var invoke = function invoke(provider, name, args) { | ||
if (provider) { | ||
var fn = provider[name]; | ||
if (typeof fn === 'function') { | ||
return provider[name].apply(provider, _toConsumableArray(args)); | ||
// Gets a property from `provider` | ||
var get = function get(provider, name) { | ||
return function () { | ||
if (provider) { | ||
return provider[name]; | ||
} | ||
} | ||
}; // Gets a property from `provider` | ||
var _get = function get(provider, name) { | ||
if (provider) { | ||
return provider[name]; | ||
} | ||
}; | ||
}; // Sets a property on `provider` | ||
var _set = function set(provider, name, value) { | ||
if (provider) { | ||
return provider[name] = value; | ||
} | ||
var set = function set(provider, name) { | ||
return function (value) { | ||
if (provider && typeof provider[name] !== 'function') { | ||
return provider[name] = value; | ||
} | ||
}; | ||
}; | ||
@@ -107,3 +92,3 @@ /** | ||
var ApiDecorator = (0, _hoc.default)(defaultConfig, function (config, Wrapped) { | ||
var _class, _temp2, _initialiseProps; | ||
var _class, _temp2; | ||
@@ -128,3 +113,17 @@ var api = config.api; | ||
return _possibleConstructorReturn(_this, (_temp = _this = _possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args))), _initialiseProps.call(_assertThisInitialized(_this)), _temp)); | ||
return _possibleConstructorReturn(_this, (_temp = _this = _possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args))), Object.defineProperty(_assertThisInitialized(_this), "setProvider", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(provider) { | ||
api.forEach(function (key) { | ||
Object.defineProperty(_assertThisInitialized(_this), key, { | ||
get: get(provider, key), | ||
set: set(provider, key), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
}); | ||
} | ||
}), _temp)); | ||
} | ||
@@ -147,38 +146,3 @@ | ||
value: 'ApiDecorator' | ||
}), _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
Object.defineProperty(this, "setProvider", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(provider) { | ||
api.forEach(function (key) { | ||
if (_this2[key]) { | ||
throw new Error("API endpoint, ".concat(key, ", already exists")); | ||
} | ||
if (typeof provider[key] === 'function') { | ||
_this2[key] = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return invoke(provider, key, args); | ||
}; | ||
} else { | ||
Object.defineProperty(_this2, key, { | ||
get: function get() { | ||
return _get(provider, key); | ||
}, | ||
set: function set(v) { | ||
return _set(provider, key, v); | ||
}, | ||
enumerable: true | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}, _temp2; | ||
}), _temp2; | ||
}); | ||
@@ -185,0 +149,0 @@ exports.ApiDecorator = ApiDecorator; |
@@ -77,3 +77,3 @@ "use strict"; | ||
}), _temp); | ||
it('should invoke arrow function on wrapped component', function () { | ||
test('should invoke arrow function on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
@@ -85,5 +85,5 @@ api: ['arrowFunction'] | ||
var actual = subject.instance().arrowFunction(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should invoke instance function on wrapped component', function () { | ||
test('should invoke instance function on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
@@ -95,5 +95,5 @@ api: ['instanceFunction'] | ||
var actual = subject.instance().instanceFunction(); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should get an instance property on wrapped component', function () { | ||
test('should get an instance property on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
@@ -105,5 +105,5 @@ api: ['instanceProperty'] | ||
var actual = subject.instance().instanceProperty; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should set an instance property on wrapped component', function () { | ||
test('should set an instance property on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
@@ -116,4 +116,4 @@ api: ['instanceProperty'] | ||
var actual = subject.instance().instanceProperty; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
}); |
@@ -140,3 +140,3 @@ "use strict"; | ||
* @function addAll | ||
* @param {Object} set A map of names to keyCodes | ||
* @param {Object<String,Number|Number[]>} set A map of names to keyCodes | ||
* | ||
@@ -143,0 +143,0 @@ * @returns {undefined} |
@@ -8,3 +8,3 @@ "use strict"; | ||
describe('keymap', function () { | ||
it('should support adding single keyCodes for a name', function () { | ||
test('should support adding single keyCodes for a name', function () { | ||
keymap.add('testEnter', 13); | ||
@@ -14,5 +14,5 @@ var expected = true; | ||
keymap.remove('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support removing a single keyCode for a name', function () { | ||
test('should support removing a single keyCode for a name', function () { | ||
keymap.add('testEnter', 13); | ||
@@ -22,5 +22,5 @@ keymap.remove('testEnter', 13); | ||
var actual = keymap.is('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support adding an array of keyCodes for a name', function () { | ||
test('should support adding an array of keyCodes for a name', function () { | ||
keymap.add('testEnter', [13, 16777221]); | ||
@@ -30,5 +30,5 @@ var expected = true; | ||
keymap.remove('testEnter', [13, 16777221]); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support removing an array of keyCodes for a name', function () { | ||
test('should support removing an array of keyCodes for a name', function () { | ||
keymap.add('testEnter', [13, 16777221]); | ||
@@ -38,5 +38,5 @@ keymap.remove('testEnter', [13, 16777221]); | ||
var actual = keymap.is('testEnter', 13) || keymap.is('testEnter', 16777221); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should support adding an map of keyCodes', function () { | ||
test('should support adding an map of keyCodes', function () { | ||
var map = { | ||
@@ -51,5 +51,5 @@ testEnter: [13, 16777221], | ||
keymap.removeAll(map); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should removing an map of keyCodes', function () { | ||
test('should removing an map of keyCodes', function () { | ||
var map = { | ||
@@ -64,5 +64,5 @@ testEnter: [13, 16777221], | ||
var actual = keymap.is('testEnter', 13) || keymap.is('testEnter', 16777221) || keymap.is('testUp', 38) || keymap.is('testDown', 40); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should use case-insensitive names', function () { | ||
test('should use case-insensitive names', function () { | ||
keymap.add('testEnter', 13); | ||
@@ -72,10 +72,10 @@ var expected = true; | ||
keymap.remove('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not add entry with a falsy name', function () { | ||
test('should not add entry with a falsy name', function () { | ||
keymap.add('', 13); | ||
var expected = false; | ||
var actual = keymap.is('', 13); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
}); |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _warning = _interopRequireDefault(require("warning")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -36,2 +38,49 @@ | ||
/** | ||
* @callback RenderFunction | ||
* @memberof core/kind | ||
* @param {Object<string, any>} props | ||
* @param {Object<string, any>} context | ||
* @returns React.Element|null | ||
*/ | ||
/** | ||
* @callback ComputedPropFunction | ||
* @memberof core/kind | ||
* @param {Object<string, any>} props | ||
* @param {Object<string, any>} context | ||
* @returns any | ||
*/ | ||
/** | ||
* @callback HandlerFunction | ||
* @memberof core/kind | ||
* @param {any} event | ||
* @param {Object<string, any>} props | ||
* @param {Object<string, any>} context | ||
*/ | ||
/** | ||
* Configuration for CSS class name mapping | ||
* | ||
* @typedef {Object} StylesBlock | ||
* @memberof core/kind | ||
* @property {Object.<string, string>} css | ||
* @property {String} [className] | ||
* @property {Boolean|String|String[]} [publicClassNames] | ||
*/ | ||
/** | ||
* @typedef {Object} KindConfig | ||
* @memberof core/kind | ||
* @property {String} name | ||
* @property {Object.<string, Function>} [propTypes] | ||
* @property {Object.<string, any>} [defaultProps] | ||
* @property {Object} [contextType] | ||
* @property {StylesBlock} [styles] | ||
* @property {Object.<string, HandlerFunction>} [handlers] | ||
* @property {Object.<string, ComputedPropFunction>} [computed] | ||
* @property {RenderFunction} render | ||
*/ | ||
/** | ||
* Creates a new component with some helpful declarative syntactic sugar. | ||
@@ -41,3 +90,3 @@ * | ||
* ``` | ||
* import css from './Button.less'; | ||
* import css from './Button.module.less'; | ||
* const Button = kind({ | ||
@@ -53,5 +102,3 @@ * // expect color and onClick properties but neither required | ||
* // expect backgroundColor via context | ||
* contextTypes: { | ||
* backgroundColor: PropTypes.string | ||
* }, | ||
* contextType: React.createContext({ backgroundColor }), | ||
* // configure styles with the static className to merge with user className | ||
@@ -83,5 +130,6 @@ * styles: { | ||
* @function | ||
* @param {Object} config Component configuration | ||
* @template Props | ||
* @param {KindConfig} config Component configuration | ||
* | ||
* @returns {Function} Component | ||
* @returns {Component<Props>} Component | ||
* @memberof core/kind | ||
@@ -94,2 +142,3 @@ * @public | ||
var cfgComputed = config.computed, | ||
contextType = config.contextType, | ||
contextTypes = config.contextTypes, | ||
@@ -102,2 +151,3 @@ defaultProps = config.defaultProps, | ||
cfgStyles = config.styles; | ||
process.env.NODE_ENV !== "production" ? (0, _warning.default)(!contextTypes, "\"contextTypes\" used by ".concat(name || 'a component', " but is deprecated. Please replace with \"contextType\" instead.")) : void 0; | ||
var renderStyles = cfgStyles ? (0, _styles.default)(cfgStyles) : false; | ||
@@ -176,2 +226,7 @@ var renderComputed = cfgComputed ? (0, _computed.default)(cfgComputed) : false; | ||
value: contextTypes | ||
}), Object.defineProperty(_class, "contextType", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: contextType | ||
}), Object.defineProperty(_class, "defaultProps", { | ||
@@ -178,0 +233,0 @@ configurable: true, |
@@ -28,3 +28,3 @@ "use strict"; | ||
}; | ||
it('should add new props to updated object', function () { | ||
test('should add new props to updated object', function () { | ||
var props = { | ||
@@ -41,5 +41,5 @@ value: true | ||
var actual = updated.count; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should overwrite properties with computed values', function () { | ||
test('should overwrite properties with computed values', function () { | ||
var props = { | ||
@@ -57,5 +57,5 @@ value: true, | ||
var actual = updated.count; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not leak updated prop values into other computed props', function () { | ||
test('should not leak updated prop values into other computed props', function () { | ||
var props = { | ||
@@ -77,16 +77,16 @@ count: 1 | ||
var actual = updated.value; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should work with its documented example - sum', function () { | ||
test('should work with its documented example - sum', function () { | ||
var updated = (0, _computed.default)(exampleCfg, exampleProps); | ||
var expected = 9; | ||
var actual = updated.sum; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should work with its documented example - product', function () { | ||
test('should work with its documented example - product', function () { | ||
var updated = (0, _computed.default)(exampleCfg, exampleProps); | ||
var expected = 24; | ||
var actual = updated.product; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
}); |
@@ -20,2 +20,4 @@ "use strict"; | ||
describe('kind', function () { | ||
var TestContext = _react.default.createContext(); | ||
var Kind = (0, _kind.default)({ | ||
@@ -30,5 +32,3 @@ name: 'Kind', | ||
}, | ||
contextTypes: { | ||
parentLabel: _propTypes.default.string | ||
}, | ||
contextType: TestContext, | ||
styles: { | ||
@@ -57,8 +57,8 @@ className: 'kind' | ||
}); | ||
it('should assign name to displayName', function () { | ||
test('should assign name to displayName', function () { | ||
var expected = 'Kind'; | ||
var actual = Kind.displayName; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should default {label} property', function () { | ||
test('should default {label} property', function () { | ||
var subject = _react.default.createElement(Kind, { | ||
@@ -70,5 +70,5 @@ prop: 1 | ||
var actual = subject.props.label; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should default {label} property when explicitly undefined', function () { | ||
test('should default {label} property when explicitly undefined', function () { | ||
// Explicitly testing for undefined | ||
@@ -83,5 +83,5 @@ // eslint-disable-next-line no-undefined | ||
var actual = subject.props.label; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should add className defined in styles', function () { | ||
test('should add className defined in styles', function () { | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Kind, { | ||
@@ -92,5 +92,5 @@ prop: 1 | ||
var actual = subject.find('div').prop('className'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should compute {value} property', function () { | ||
test('should compute {value} property', function () { | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Kind, { | ||
@@ -101,11 +101,11 @@ prop: 1 | ||
var actual = subject.find('div').prop('children'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should assign contextTypes when handlers are specified', function () { | ||
var actual = Kind.contextTypes != null; | ||
test('should assign contextType when handlers are specified', function () { | ||
var actual = Kind.contextType != null; | ||
var expected = true; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
describe('inline', function () { | ||
it('should support a minimal kind', function () { | ||
test('should support a minimal kind', function () { | ||
var Minimal = (0, _kind.default)({ | ||
@@ -120,5 +120,5 @@ name: 'Minimal', | ||
var actual = component.type; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should set default props when prop is not passed', function () { | ||
test('should set default props when prop is not passed', function () { | ||
var component = Kind.inline(); // since we're inlining the output, we have to reference where the label prop lands -- | ||
@@ -130,5 +130,5 @@ // the title prop of the <div> -- rather than the label prop on the component (which | ||
var actual = component.props.title; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should set default props when passed prop is undefined', function () { | ||
test('should set default props when passed prop is undefined', function () { | ||
var component = Kind.inline({ | ||
@@ -141,5 +141,5 @@ // explicitly testing settings undefined in this test case | ||
var actual = component.props.title; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should include handlers', function () { | ||
test('should include handlers', function () { | ||
var component = Kind.inline(); | ||
@@ -150,5 +150,5 @@ var expected = 'function'; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
}); |
@@ -15,3 +15,3 @@ "use strict"; | ||
it('should add cfg.className to props', function () { | ||
test('should add cfg.className to props', function () { | ||
var cfg = { | ||
@@ -23,5 +23,5 @@ className: 'button' | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should resolve cfg.className to the cfg.css map', function () { | ||
test('should resolve cfg.className to the cfg.css map', function () { | ||
var cfg = { | ||
@@ -34,5 +34,5 @@ css: css, | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should pass through props.className when cfg.className absent', function () { | ||
test('should pass through props.className when cfg.className absent', function () { | ||
var props = { | ||
@@ -44,5 +44,5 @@ className: 'button' | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should append cfg.className with props.className', function () { | ||
test('should append cfg.className with props.className', function () { | ||
var props = { | ||
@@ -57,5 +57,5 @@ className: 'custom-button' | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should resolve cfg.className and append with props.className', function () { | ||
test('should resolve cfg.className and append with props.className', function () { | ||
var props = { | ||
@@ -71,6 +71,6 @@ className: 'custom-button' | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); // style tests | ||
it('should add cfg.style to props', function () { | ||
test('should add cfg.style to props', function () { | ||
var cfg = { | ||
@@ -84,5 +84,5 @@ style: { | ||
var actual = updated.style.color; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should pass through props.style when cfg.style absent', function () { | ||
test('should pass through props.style when cfg.style absent', function () { | ||
var props = { | ||
@@ -96,5 +96,5 @@ style: { | ||
var actual = updated.style.color; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should merge cfg.style and props.style', function () { | ||
test('should merge cfg.style and props.style', function () { | ||
var props = { | ||
@@ -113,7 +113,7 @@ style: { | ||
var actual = Object.keys(updated.style).length; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); // Doesn't support merging shorthand properties and individual properties | ||
// e.g. borderWidth: 3px + border: 1px solid black = border: 3px solid black | ||
it('should not merge shorthand properties', function () { | ||
test('should not merge shorthand properties', function () { | ||
var props = { | ||
@@ -132,6 +132,6 @@ style: { | ||
var actual = Object.keys(updated.style).length; | ||
expect(actual).to.not.equal(expected); | ||
expect(actual).not.toBe(expected); | ||
}); // styler tests | ||
it('should add styler.join() to props', function () { | ||
test('should add styler.join() to props', function () { | ||
var updated = (0, _styles.default)({}, {}); | ||
@@ -142,11 +142,11 @@ var expected = 'function'; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should join classes together with a space', function () { | ||
test('should join classes together with a space', function () { | ||
var updated = (0, _styles.default)({}, {}); | ||
var expected = 'abc def'; | ||
var actual = updated.styler.join('abc', 'def'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should resolve join classes to css map', function () { | ||
test('should resolve join classes to css map', function () { | ||
var updated = (0, _styles.default)({ | ||
@@ -157,5 +157,5 @@ css: css | ||
var actual = updated.styler.join('button', 'client'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not resolve author classes to css map', function () { | ||
test('should not resolve author classes to css map', function () { | ||
var cfg = { | ||
@@ -171,5 +171,5 @@ css: css, | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should append resolved class names to props.className', function () { | ||
test('should append resolved class names to props.className', function () { | ||
var cfg = { | ||
@@ -185,4 +185,4 @@ css: css, | ||
var actual = updated.styler.append('client'); | ||
expect(actual).to.equal(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
}); |
{ | ||
"name": "@enact/core", | ||
"version": "2.2.9", | ||
"version": "2.3.0-alpha.1", | ||
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.", | ||
@@ -9,5 +9,5 @@ "main": "index.js", | ||
"lint": "enact lint --strict", | ||
"test": "enact test start --single-run --browsers PhantomJS", | ||
"test-json": "enact test start --single-run --browsers PhantomJS --reporters json", | ||
"test-watch": "enact test start --browsers PhantomJS", | ||
"test": "enact test", | ||
"test-json": "enact test --json", | ||
"test-watch": "enact test --watch", | ||
"transpile": "enact transpile" | ||
@@ -34,8 +34,9 @@ }, | ||
"invariant": "^2.2.2", | ||
"prop-types": "^15.6.0", | ||
"prop-types": "15.6.2", | ||
"ramda": "^0.24.1", | ||
"react": "^16.3.2", | ||
"react-dom": "^16.3.2", | ||
"recompose": "^0.26.0" | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0", | ||
"recompose": "^0.26.0", | ||
"warning": "^3.0.0" | ||
} | ||
} |
@@ -144,8 +144,18 @@ "use strict"; | ||
/** | ||
* @typedef {Object} PlatformDescription | ||
* @property {Boolean} gesture - `true` if the platform has native double-finger events | ||
* @property {Boolean} node - `true` only if `window` is `undefined` | ||
* @property {String} platformName - The name of the platform | ||
* @property {Boolean} touch - `true` if the platform has native single-finger events | ||
* @property {Boolean} unknown - `true` for any unknown system | ||
* | ||
* @memberof core/platform | ||
* @public | ||
*/ | ||
/** | ||
* Returns the {@link core/platform.platform} object. | ||
* | ||
* @function | ||
* @returns {Object} The {@link core/platform.platform} object | ||
* | ||
* @method detect | ||
* @function detect | ||
* @returns {PlatformDescription} The {@link core/platform.platform} object | ||
* @memberof core/platform | ||
@@ -205,10 +215,3 @@ * @public | ||
* | ||
* @readonly | ||
* @type {Object} | ||
* @property {Boolean} gesture - `true` if the platform has native double-finger events | ||
* @property {Boolean} node - `true` only if `window` is `undefined` | ||
* @property {String} platformName - The name of the platform | ||
* @property {Boolean} touch - `true` if the platform has native single-finger events | ||
* @property {Boolean} unknown - `true` for any unknown system | ||
* | ||
* @type {PlatformDescription} | ||
* @memberof core/platform | ||
@@ -215,0 +218,0 @@ * @public |
@@ -27,3 +27,3 @@ # @enact/core [![npm (scoped)](https://img.shields.io/npm/v/@enact/core.svg?style=flat-square)](https://www.npmjs.com/package/@enact/core) | ||
Copyright (c) 2012-2018 LG Electronics | ||
Copyright (c) 2012-2019 LG Electronics | ||
@@ -30,0 +30,0 @@ Unless otherwise specified or set forth in the NOTICE file, all content, including all source code files and documentation files in this repository are: Licensed under the Apache License, Version 2.0 (the "License"); you may not use this content except in compliance with the License. You may obtain a copy of the License at |
@@ -8,2 +8,6 @@ "use strict"; | ||
var _invariant = _interopRequireDefault(require("invariant")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -45,3 +49,3 @@ | ||
// don't want to inadvertently apply Job's context on `fn` | ||
this.fn.apply(null, args); | ||
return this.fn.apply(null, args); | ||
} | ||
@@ -132,7 +136,7 @@ /** | ||
window.cancelAnimationFrame(_this.id); | ||
} else { | ||
} else if (_this.type === 'timeout') { | ||
clearTimeout(_this.id); | ||
} | ||
_this.id = null; | ||
_this.id = _this.type = null; | ||
} | ||
@@ -257,2 +261,19 @@ } | ||
}); | ||
Object.defineProperty(this, "promise", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(promise) { | ||
!(promise && typeof promise.then === 'function') ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, 'promise expects a thenable') : invariant(false) : void 0; | ||
_this.type = 'promise'; | ||
_this.id = promise; | ||
return promise.then(function (result) { | ||
if (_this.id === promise) { | ||
_this.stop(); | ||
return _this.run([result]); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
@@ -259,0 +280,0 @@ |
@@ -9,7 +9,7 @@ "use strict"; | ||
describe('#start', function () { | ||
it('should start job', function (done) { | ||
test('should start job', function (done) { | ||
var j = new _Job.default(done, 10); | ||
j.start(); | ||
}); | ||
it('should pass args to fn', function (done) { | ||
test('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
@@ -30,3 +30,3 @@ | ||
describe('#stop', function () { | ||
it('should stop job', function (done) { | ||
test('should stop job', function (done) { | ||
var ran = false; | ||
@@ -45,3 +45,3 @@ var j = new _Job.default(function () { | ||
describe('#throttle', function () { | ||
it('should throttle job', function (done) { | ||
test('should throttle job', function (done) { | ||
var number = 0; | ||
@@ -69,3 +69,3 @@ var j = new _Job.default(function () { | ||
}); | ||
it('should pass args to fn', function (done) { | ||
test('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
@@ -89,3 +89,3 @@ | ||
var windowCancel = window.cancelIdleCallback; | ||
before(function () { | ||
beforeAll(function () { | ||
window.requestIdleCallback = windowRequest || function (fn) { | ||
@@ -99,11 +99,11 @@ return setTimeout(fn, 0); | ||
}); | ||
after(function () { | ||
afterAll(function () { | ||
window.requestIdleCallback = windowRequest; | ||
window.cancelIdleCallback = windowCancel; | ||
}); | ||
it('should start job', function (done) { | ||
test('should start job', function (done) { | ||
var j = new _Job.default(done, 10); | ||
j.idle(); | ||
}); | ||
it('should pass args to fn', function (done) { | ||
test('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
@@ -122,3 +122,3 @@ | ||
}); | ||
it('should clear an existing job id before starting job', function (done) { | ||
test('should clear an existing job id before starting job', function (done) { | ||
var fn = function fn(arg) { | ||
@@ -137,2 +137,88 @@ if (arg === 'first') { | ||
}); | ||
describe('#promise', function () { | ||
test('should throw when passed a non-thenable argument', function (done) { | ||
var j = new _Job.default(function () { | ||
return done(new Error('Unexpected job execution')); | ||
}); | ||
try { | ||
j.promise({}); | ||
} catch (msg) { | ||
done(); | ||
} | ||
}); | ||
test('should support a non-Promise, thenable argument', function (done) { | ||
var j = new _Job.default(function () { | ||
return done(); | ||
}); | ||
try { | ||
j.promise({ | ||
then: function then(fn) { | ||
return fn(true); | ||
} | ||
}); | ||
} catch (msg) { | ||
done(msg); | ||
} | ||
}); | ||
test('should start job for a resolved promise', function (done) { | ||
var j = new _Job.default(function () { | ||
return done(); | ||
}); | ||
j.promise(Promise.resolve(true)); | ||
}); | ||
test('should not start job for a rejected promise', function (done) { | ||
var j = new _Job.default(function () { | ||
done(new Error('Job ran for rejected promise')); | ||
}); | ||
j.promise(Promise.reject(true)).catch(function () {}); | ||
setTimeout(done, 10); | ||
}); | ||
test('should not start job when stopped before promise resolves', function (done) { | ||
var j = new _Job.default(function () { | ||
done(new Error('Job ran for stopped promise')); | ||
}); | ||
j.promise(new Promise(function (resolve) { | ||
return setTimeout(resolve, 20); | ||
})); | ||
setTimeout(function () { | ||
return j.stop(); | ||
}, 10); | ||
setTimeout(done, 30); | ||
}); | ||
test('should not start job when another is started', function (done) { | ||
var j = new _Job.default(function (value) { | ||
expect(value).toBe(2); | ||
done(); | ||
}); | ||
j.promise(new Promise(function (resolve) { | ||
return resolve(1); | ||
})); | ||
j.promise(new Promise(function (resolve) { | ||
return resolve(2); | ||
})); | ||
}); | ||
test('should return the value from the job to the resolved promise', function (done) { | ||
var j = new _Job.default(function () { | ||
return 'job value'; | ||
}); | ||
j.promise(Promise.resolve(true)).then(function (value) { | ||
expect(value).toBe('job value'); | ||
done(); | ||
}); | ||
}); | ||
test('should not return the value from the job to the replaced promise', function (done) { | ||
var j = new _Job.default(function () { | ||
return 'job value'; | ||
}); | ||
j.promise(Promise.resolve(true)).then(function (value) { | ||
expect(value).toBeUndefined(); | ||
done(); | ||
}); | ||
j.promise(Promise.resolve(true)).then(function () { | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); |
"use strict"; | ||
var _sinon = _interopRequireDefault(require("sinon")); | ||
var _ = require(".."); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('memoize', function () { | ||
it('should memoize function', function () { | ||
test('should memoize function', function () { | ||
var obj = {}, | ||
@@ -17,18 +13,17 @@ testMethod = function testMethod(key) { | ||
expect(obj).not.to.have.property('a'); | ||
expect(obj).not.toHaveProperty('a'); | ||
memoizedTest('a'); | ||
expect(obj).to.have.property('a', 1); | ||
expect(obj).toHaveProperty('a', 1); | ||
memoizedTest('a'); | ||
memoizedTest('a'); | ||
expect(obj).to.have.property('a', 1); | ||
expect(obj).toHaveProperty('a', 1); | ||
}); | ||
it('should forward all args to memoized function', function () { | ||
var spy = _sinon.default.spy(); | ||
test('should forward all args to memoized function', function () { | ||
var spy = jest.fn(); | ||
var memoized = (0, _.memoize)(spy); | ||
memoized(1, 2); | ||
var expected = [1, 2]; | ||
var actual = spy.firstCall.args; | ||
expect(expected).to.deep.equal(actual); | ||
var actual = spy.mock.calls[0]; | ||
expect(expected).toEqual(actual); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169515
56
4598
8
2
8
+ Addedwarning@^3.0.0
+ Addedprop-types@15.6.2(transitive)
+ Addedwarning@3.0.0(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact-is@16.13.1(transitive)
Updatedprop-types@15.6.2
Updatedreact@^16.7.0
Updatedreact-dom@^16.7.0