Skip to content

Commit

Permalink
[added] testing-utils
Browse files Browse the repository at this point in the history
Summary:
Gives us a place to put testing utilities.  I also expect to put `useMockedRAF` here, removing the need for `waitAFrame`.  That work is currently blocked on the landing of FormidableLabs/mock-raf#6

If that doesn't land, I'll fork mock-raf and add it here too.

Reviewers: O3 Material JavaScript platform reviewers, #material_motion, O2 Material Motion, featherless

Reviewed By: #material_motion, O2 Material Motion, featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D2411
  • Loading branch information
appsforartists committed Dec 22, 2016
1 parent b353d28 commit c5d8089
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/testing-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Material Motion Testing Utils #

Utilities for testing the Material Motion framework

## Usage ##

```javascript
import {
createMockObserver,
} from 'material-motion-testing-utils';

const mockObserver = createMockObserver();

const someStream = new MotionObservable(mockObserver);
someStream.subscribe(someListener);
mockObserver.next(5);
expect(someListener).to.have.been.calledWith(5);
```

## Installation ##

```
yarn add material-motion-testing-utils
```

## License ##

[Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0)
39 changes: 39 additions & 0 deletions packages/testing-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "material-motion-testing-utils",
"version": "0.0.0",
"description": "Utilities for testing the Material Motion framework",
"main": "dist/index.js",
"types": "src/index.ts",
"scripts": {
"clean": "rm -rf ./dist/*; mkdir -p ./dist/",
"build": "yarn run clean; ../../node_modules/.bin/tsc"
},
"peerDependencies": {
"sinon": "2.0.0-pre.3"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:material-motion/material-motion-js.git"
},
"keywords": [
"animation",
"gestures",
"interactive",
"material",
"motion",
"multitouch",
"observables",
"odeon",
"physics",
"springs",
"touch",
"transitions",
"tweens"
],
"author": "The Material Motion Authors (see AUTHORS)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/material-motion/material-motion-js/issues/"
},
"homepage": "https://github.com/material-motion/material-motion-js/tree/develop/packages/testing-utils/#readme"
}
36 changes: 36 additions & 0 deletions packages/testing-utils/src/createMockObserver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @license
* Copyright 2016 - present The Material Motion Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

import {
stub,
} from 'sinon';

export default function createMockObserver() {
return new MockObserver();
}

export class MockObserver {
next?: Function;
state?: Function;
disconnect = stub();

connect = (observer) => {
this.next = observer.next;
this.state = observer.state;

return this.disconnect;
}
}
18 changes: 18 additions & 0 deletions packages/testing-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @license
* Copyright 2016 - present The Material Motion Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

export * from './createMockObserver';
export { default as createMockObserver } from './createMockObserver';
14 changes: 14 additions & 0 deletions packages/testing-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.json",
"include": ["./src/**/*"],
"exclude": [],
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"noImplicitAny": false,
"noImplicitThis": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"strictNullChecks": false
}
}

0 comments on commit c5d8089

Please sign in to comment.