{"__v":18,"_id":"55c3408eb6e05719008a045a","category":{"__v":11,"_id":"55bf16593179dd1900a19521","pages":["55bf2050e2eec72d00d8c4a4","55bf690cad601c2b00762d06","55bf69538b83a53700445077","55bf698f8b83a5370044507a","55bf69b703d092210084c143","55bf6a0303d092210084c146","55c33c718713ec1900d17318","55c3407d8713ec1900d1731e","55c3408eb6e05719008a045a","55c34298b6e05719008a0464","55c342d68713ec1900d17327"],"project":"55a92d71cf45e1390093f321","version":"55a92d71cf45e1390093f324","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-08-03T07:20:57.407Z","from_sync":false,"order":1,"slug":"jasmine","title":"Jasmine"},"parentDoc":null,"project":"55a92d71cf45e1390093f321","user":"55a4738a68c7e20d0036d4de","version":{"__v":12,"_id":"55a92d71cf45e1390093f324","project":"55a92d71cf45e1390093f321","createdAt":"2015-07-17T16:29:37.746Z","releaseDate":"2015-07-17T16:29:37.746Z","categories":["55a92d72cf45e1390093f325","55b9aea1baf4cd2300bc56e7","55bf16593179dd1900a19521","55bf16b93179dd1900a19525","55bf16c53bbd4b17002c2369","55bf234703d092210084c07b","55bf2859ad601c2b00762c4c","55bf3217ad601c2b00762c69","55bf321b03d092210084c09d","55bf5ef78b83a5370044504e","55c345418713ec1900d1732d","55c3473057f7f32d0016ec0a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["55cb5d6a50046e3700d90f03","55da33bfd034820d00faccc6"],"next":{"pages":[],"description":""},"createdAt":"2015-08-06T11:10:06.924Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"You can also test packages directly in isolation. You can find an example package [here](https://github.com/Sanjo/meteor-jasmine/tree/master/test-app/packages/package-to-test).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Add sanjo:jasmine to your package\"\n}\n[/block]\nAdd or replace the `Package.onTest` block in your package.js.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Package.onTest(function(api) {\\n  api.use('package-to-test');\\n  api.use('sanjo:jasmine:::at:::1.0.0');\\n  api.use('velocity:html-reporter@0.10.0');\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"package.js\"\n    }\n  ]\n}\n[/block]\nIt's important that you specify the version explicitly. Otherwise Meteor uses an outdated version.\nAlso you need to use the package that you test in the onTest block.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Create tests\"\n}\n[/block]\nCreate your first test. The file can be anywhere in your package. I recommend to put them in the tests folder for consistency with your app tests.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"describe('sanjo:jasmine on client', function () {\\n  it('works', function () {\\n    expect(it).toBeDefined();\\n  })\\n})\",\n      \"language\": \"javascript\",\n      \"name\": \"tests/client/example-spec.js\"\n    },\n    {\n      \"code\": \"describe('sanjo:jasmine on server', function () {\\n  it('works', function () {\\n    expect(it).toBeDefined();\\n  })\\n})\",\n      \"language\": \"javascript\",\n      \"name\": \"tests/server/example-spec.js\"\n    },\n    {\n      \"code\": \"describe('sanjo:jasmine on client and server', function () {\\n  it('works', function () {\\n    expect(it).toBeDefined();\\n  })\\n})\",\n      \"language\": \"javascript\",\n      \"name\": \"tests/example-spec.js\"\n    }\n  ]\n}\n[/block]\nAnd then add the tests files to the `Package.onTest` block in your package.js\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Package.onTest(function(api) {\\n  api.use('package-to-test');\\n  api.use('sanjo:jasmine@1.0.0');\\n  api.use('velocity:html-reporter@0.10.0');\\n  \\n  api.addFiles('tests/server/example-spec.js', 'server');\\n  api.addFiles('tests/client/example-spec.js', 'client');\\n  api.addFiles('tests/example-spec.js', ['client', 'server']);\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"package.js\"\n    }\n  ]\n}\n[/block]\nThe architecture that you define for your test files will determine if it is a server or client tests. A test can also be executed on the client and the server.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Execute tests\"\n}\n[/block]\n```bash\nmeteor test-packages --driver-package=sanjo:jasmine package-to-test\n```\n\nIf your package is not located in an app you can test it with:\n\n```bash\nmeteor test-packages --driver-package=sanjo:jasmine ./\n```\n\nIf you want to debug your server code, just add `--debug-port 5858` as argument to the command.\n\nIf you want to run your package tests besides your app, specify a free port by adding `--port 5000`.\n\nYou can find a list of all available command options [here](https://github.com/meteor/meteor/blob/120febbf8a40f262e436d907ff36e469a19d7698/tools/commands.js#L1295-L1339).","excerpt":"","slug":"jasmine-testing-a-meteor-package","type":"basic","title":"Package testing"}
You can also test packages directly in isolation. You can find an example package [here](https://github.com/Sanjo/meteor-jasmine/tree/master/test-app/packages/package-to-test). [block:api-header] { "type": "basic", "title": "1. Add sanjo:jasmine to your package" } [/block] Add or replace the `Package.onTest` block in your package.js. [block:code] { "codes": [ { "code": "Package.onTest(function(api) {\n api.use('package-to-test');\n api.use('sanjo:jasmine@1.0.0');\n api.use('velocity:html-reporter@0.10.0');\n});", "language": "javascript", "name": "package.js" } ] } [/block] It's important that you specify the version explicitly. Otherwise Meteor uses an outdated version. Also you need to use the package that you test in the onTest block. [block:api-header] { "type": "basic", "title": "2. Create tests" } [/block] Create your first test. The file can be anywhere in your package. I recommend to put them in the tests folder for consistency with your app tests. [block:code] { "codes": [ { "code": "describe('sanjo:jasmine on client', function () {\n it('works', function () {\n expect(it).toBeDefined();\n })\n})", "language": "javascript", "name": "tests/client/example-spec.js" }, { "code": "describe('sanjo:jasmine on server', function () {\n it('works', function () {\n expect(it).toBeDefined();\n })\n})", "language": "javascript", "name": "tests/server/example-spec.js" }, { "code": "describe('sanjo:jasmine on client and server', function () {\n it('works', function () {\n expect(it).toBeDefined();\n })\n})", "language": "javascript", "name": "tests/example-spec.js" } ] } [/block] And then add the tests files to the `Package.onTest` block in your package.js [block:code] { "codes": [ { "code": "Package.onTest(function(api) {\n api.use('package-to-test');\n api.use('sanjo:jasmine@1.0.0');\n api.use('velocity:html-reporter@0.10.0');\n \n api.addFiles('tests/server/example-spec.js', 'server');\n api.addFiles('tests/client/example-spec.js', 'client');\n api.addFiles('tests/example-spec.js', ['client', 'server']);\n});", "language": "javascript", "name": "package.js" } ] } [/block] The architecture that you define for your test files will determine if it is a server or client tests. A test can also be executed on the client and the server. [block:api-header] { "type": "basic", "title": "3. Execute tests" } [/block] ```bash meteor test-packages --driver-package=sanjo:jasmine package-to-test ``` If your package is not located in an app you can test it with: ```bash meteor test-packages --driver-package=sanjo:jasmine ./ ``` If you want to debug your server code, just add `--debug-port 5858` as argument to the command. If you want to run your package tests besides your app, specify a free port by adding `--port 5000`. You can find a list of all available command options [here](https://github.com/meteor/meteor/blob/120febbf8a40f262e436d907ff36e469a19d7698/tools/commands.js#L1295-L1339).