Like Ian said, most people create a test database. but ideally it is much faster and better to use a mocked database. It's easiest for couchdb since it uses http to communicate. For that you could use https://github.com/flatiron/nock
you don't even have to mock the connection. if you know the database module you're using is well tested, mock that module. http://howtonode.org/testing-private-state-and-mocking-deps On Saturday, March 10, 2012 4:31:21 PM UTC-7, Martin Lundberg wrote: > > I've got an object named UserRepository which has a method named find > which uses node-mysql to fetch rows from the database and I'm confused on > how to test this code. I've tried reading about mocks but I still can't > figure out exactly how to test the code. How do you test code which talks > to a database? > > I've also read "only mock what you own" and since I don't own node-mysql > client I'm not sure what to do. > > Would really appreciate examples. > > Thanks, > > -Martin > On Saturday, March 10, 2012 4:31:21 PM UTC-7, Martin Lundberg wrote: > > I've got an object named UserRepository which has a method named find > which uses node-mysql to fetch rows from the database and I'm confused on > how to test this code. I've tried reading about mocks but I still can't > figure out exactly how to test the code. How do you test code which talks > to a database? > > I've also read "only mock what you own" and since I don't own node-mysql > client I'm not sure what to do. > > Would really appreciate examples. > > Thanks, > > -Martin > On Saturday, March 10, 2012 4:31:21 PM UTC-7, Martin Lundberg wrote: > > I've got an object named UserRepository which has a method named find > which uses node-mysql to fetch rows from the database and I'm confused on > how to test this code. I've tried reading about mocks but I still can't > figure out exactly how to test the code. How do you test code which talks > to a database? > > I've also read "only mock what you own" and since I don't own node-mysql > client I'm not sure what to do. > > Would really appreciate examples. > > Thanks, > > -Martin > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
