{"_id":"@atlassian/jasmine-http-server-spy","name":"@atlassian/jasmine-http-server-spy","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@atlassian/jasmine-http-server-spy","version":"1.0.0","description":"Creates jasmine spy objects backed by a http server.","main":"lib/jasmine-http-server-spy.js","scripts":{"test":"grunt","prepublish":"npm run compile","compile":"grunt compile","release:prep:major":"node ./bin/release-prep.js major","release:prep:minor":"node ./bin/release-prep.js minor","release:prep:patch":"node ./bin/release-prep.js patch","release:prep:prerelease":"node ./bin/release-prep.js prerelease","release:publish":"./bin/publish-release.sh"},"repository":{"type":"git","url":"git+https://bitbucket.org/atlassian/jasmine-http-server-spy.git"},"bugs":{"url":"https://bitbucket.org/atlassian/jasmine-http-server-spy/issues"},"keywords":["jasmine","mock-server","spy","test","integration"],"author":{"name":"Aleksandr Motsjonov","email":"amotsjonov@atlassian.com"},"license":"Apache-2.0","publishConfig":{"registry":"https://packages.atlassian.com/api/npm/npm-public/"},"engines":{"node":"<=18"},"devDependencies":{"grunt":"^1.0.4","grunt-cli":"^1.3.2","grunt-contrib-clean":"^2.0.0","grunt-contrib-coffee":"^2.1.0","grunt-contrib-watch":"^1.1.0","grunt-shell":"^3.0.1","jasmine":"^2.3.1","jasmine-reporters":"^2.0.7","load-grunt-tasks":"^4.0.0","request":"^2.88.0","typescript":"^1.6.2"},"dependencies":{"body-parser":"^1.19.0","debug":"^4.1.1","express":"^4.16.4","lodash":"^4.17.11","q":"^1.5.1"},"_id":"@atlassian/jasmine-http-server-spy@1.0.0","homepage":"https://bitbucket.org/atlassian/jasmine-http-server-spy#readme","_integrity":"sha512-OI5JgbgzDLqwOFaw0RtEiGAMwmu9WyPRzkwJw1OMdC+Y5lwKe6gEPVZSM7hsdsg8tOEan3/qQZ1bdTnuv2XA1Q==","_resolved":"/tmp/package-1-6a02154b-091e757c42d0a6a49da1a5d6-1.tgz","_from":"file:/tmp/package-1-6a02154b-091e757c42d0a6a49da1a5d6-1.tgz","_nodeVersion":"20.20.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-OI5JgbgzDLqwOFaw0RtEiGAMwmu9WyPRzkwJw1OMdC+Y5lwKe6gEPVZSM7hsdsg8tOEan3/qQZ1bdTnuv2XA1Q==","shasum":"8f086359a7f46c22906b447daa98215e1e3d02bf","tarball":"https://registry.npmjs.org/@atlassian/jasmine-http-server-spy/-/jasmine-http-server-spy-1.0.0.tgz","fileCount":21,"unpackedSize":167919,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEuox4T8X125wVm1n5wguSR/J+TrviBzAeRKcJr3qRFMAiEAhhEyo0ou4x9NvvWA3nPOfuDdgEp6s1ZQaDlfwomDv58="}]},"_npmUser":{"name":"atlassianartifactteam","email":"eng-development-tooling-artifacts@atlassian.com"},"directories":{},"maintainers":[{"name":"atlassianartifactteam","email":"eng-development-tooling-artifacts@atlassian.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jasmine-http-server-spy_1.0.0_1778521423168_0.02858695191981231"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-11T17:43:43.056Z","1.0.0":"2026-05-11T17:43:43.373Z","modified":"2026-05-11T17:43:43.563Z"},"maintainers":[{"name":"atlassianartifactteam","email":"eng-development-tooling-artifacts@atlassian.com"}],"description":"Creates jasmine spy objects backed by a http server.","homepage":"https://bitbucket.org/atlassian/jasmine-http-server-spy#readme","keywords":["jasmine","mock-server","spy","test","integration"],"repository":{"type":"git","url":"git+https://bitbucket.org/atlassian/jasmine-http-server-spy.git"},"author":{"name":"Aleksandr Motsjonov","email":"amotsjonov@atlassian.com"},"bugs":{"url":"https://bitbucket.org/atlassian/jasmine-http-server-spy/issues"},"license":"Apache-2.0","readme":"# jasmine-http-server-spy\n\n> Creates jasmine spy objects backed by a http server. Designed to help you write integration tests where your code\nmakes real http requests to a server, where the server is controlled via the familiar jasmine spy api.\n\n## Install\n\n```sh\nnpm install --save jasmine-http-server-spy\n```\n\n## API\n\n### Server API by example\n\n```javascript\nvar jasmineHttpServerSpy = require('jasmine-http-server-spy');\n\ndescribe('Test', function() {\n  beforeAll(function(done) {\n    this.httpSpy = jasmineHttpServerSpy.createSpyObj('mockServer', [\n      {\n        method: 'get',\n        url: '/some-url-to-mock',\n        handlerName: 'getSomeUrlToMock'\n      }\n    ]);\n    this.httpSpy.server.start(8082, done);\n    // you can pass jasmine 'done' function as a callback, or use returned promise\n    // this.httpSpy.server.start(8082).then(done, done.fail);\n    // you can also specify the hostname to start the server on:\n    // this.httpSpy.server.start(8082, '127.0.0.1').then(done, done.fail);\n    // this is useful if you need to test multiple servers listening on the same port\n  });\n\n  afterAll(function(done) {\n    this.httpSpy.server.stop(done)\n    // you can pass jasmine 'done' function as a callback, or use returned promise:\n    // this.httpSpy.server.stop().then(done, done.fail);\n  });\n\n  afterEach(function() {\n    this.httpSpy.getSomeUrlToMock.calls.reset();\n  });\n\n  it('all the things', function() {\n    // 1. Define what mock server would return\n    this.httpSpy.getSomeUrlToMock.and.returnValue({\n      statusCode: 200,\n      body: {\n        data: 10\n      }\n    });\n\n    // 2. ... calls to main service that uses 'http://localhost:8082/some-url-to-mock'\n\n    // 3. Assert mock server has been called as expected\n    expect(this.httpSpy.getSomeUrlToMock).toHaveBeenCalled();\n\n    // or\n    expect(this.httpSpy.getSomeUrlToMock).toHaveBeenCalledWith(jasmine.objectContaining({\n      body: {\n        data: \"something\"\n      }\n    }));\n  });\n\n  it('can accept promise as handler returnValue', function() {\n    var deferred = q.defer();\n    this.httpSpy.getSomeUrlToMock.and.returnValue(deferred.promise);\n    setTimeout(function(){\n        deferred.resolve({\n          statusCode: 200,\n           body: {\n             data: 10\n           }\n        });\n    });\n  });\n});\n```\n\n### Handler's expected output\n\nHandler function result will end up in the http response mock server gives back.\nYou can define ```code```, ```body``` and ```headers``` at the moment:\n\n```coffee\nhttpSpy.getSomeUrlToMock.and.returnValue {code: 200, body: {data: []}}\n\nhttpSpy.getSomeUrlToMock.and.returnValue {code: 200, body: '<xml>...</xml>', headers: {'Content-Type' : 'application/xml'}}\n\nhttpSpy.getSomeUrlToMock.and.returnValue {code: 401, body: {message: 'Please login first'}}\n```\n\n### Handler's input\n\nWhile handlers are jasmine spy objects, you can define a callback function to make response dynamic. For example:\n\n```coffee\nhttpSpy.getAnswerForANumber.and.callFake (req) ->\n    code: 200\n    body:\n        if req.body.number is 42\n            {answer: 'The answer to the ultimate question of life, the universe and everything'}\n        else\n            {answer: \"I don't know\"}\n```\n\nYou can expect following properties in the first argument of this callback:\n\n#### body\n\nJS Object representing JSON body of a request. This object defaults to ```{}```.\n\n#### query\n\nObject containing all query parameters used. This object defaults to ```{}```.\n\n#### originalUrl\n\nRequested original URL. For example request to ```http://localhost:8082/mockService/users?something``` end up as\n```/mockService/users?something``` in ```originalUrl```\n\n#### headers\n\nObject containing all headers provided with request.\n\n#### params\n\nAn object containing properties mapped to the named route \"parameters\".\nFor example, if you have the route ```/user/:name```, then the \"name\" property is available as ```req.params.name```.\nThis object defaults to ```{}```.\n\n## Changelog\n\n### 0.4.2\n\nUpdate dependencies.\n\n### 0.4.1\n\n- Return 500 if spy returns undefined.\n- Return 500 if spy returns a rejected Promise.\n\n### 0.4.0\n\nSupport JSON sub-types like application/scim+json\n\n### 0.3.1\n\n`start` now accepts hostname as optional second parameter `start(8082, '127.0.0.1')`\n\n### 0.3.0\n\n`start` and `stop` function return promise now. Use of jasmine `done` callback is now optional.\n\n## Contribute\n\nFeel free to fork and make pull requests:\nhttps://bitbucket.org/atlassian/jasmine-http-server-spy/fork\n\nIssues and suggestions can be added here:\nhttps://bitbucket.org/atlassian/jasmine-http-server-spy/issues\n","readmeFilename":"README.md","_rev":"1-783cdb139f328807f28e33a96ad19def"}