mirror of https://github.com/google/pebble
				
				
				
			| 
				
					
						
							 | 
			||
|---|---|---|
| .. | ||
| .eslintrc.js | ||
| .gitignore | ||
| README.md | ||
| package.json | ||
| pebble-mock.js | ||
| test_message.js | ||
		
			
				
				README.md
			
		
		
			
			
				
				
			
		
	
	sdk/include/*.js unit testing how-to
This folder contains tests for the .js code in sdk/include.
Installing dependencies
cd sdk/tests/includenpm install
Running tests
cd sdk/tests/includenpm test– this runs the tests using the mocha test runner.
You should see some output, similar to this:
$ npm test
> pebble-pkjs-tests@1.0.0 test /Users/martijn/tintin/sdk/tests/include
> NODE_PATH=../include ./node_modules/mocha/bin/mocha *.js
  Pebble
    interprets received postMessage API data as UTF-8
      ✓ interprets [34,34] as ""
      ✓ interprets [34,240,159,146,169,34] as "💩"
      ✓ interprets [34,237,160,181,237,188,128,34] as {}
      ✓ interprets [34,196,145,34] as "đ"
      ✓ interprets [34,224,160,149,34] as "ࠕ"
    encodes sent postMessage API data as UTF-8
sendAppMessage: [object Object]
      ✓ encodes "" as [34,34,0]
sendAppMessage: [object Object]
      ✓ encodes "💩" as [34,240,159,146,169,34,0]
sendAppMessage: [object Object]
      ✓ encodes "đ" as [34,196,145,34,0]
sendAppMessage: [object Object]
      ✓ encodes "ࠕ" as [34,224,160,149,34,0]
  9 passing (25ms)
Linting the test code
cd sdk/tests/includenpm run-script lint
Adding tests
- You can add 
test_xyz.jsfiles in thetestsfolder. It will automatically get picked up by the test runner. - If you need to a mock for the global 
Pebbleobject, check outpebble-mock.js. It's probably worth using and extending that than to re-invent the wheel. - When adding additional dependencies (node packages), make sure to install them using 
npm install --save-dev <PACKAGE_NAME>so that they get added to thedevDependenciesin thepackage.jsonfile.