You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`import { Polly } from '@pollyjs/core';
import { expect } from 'chai'; // Chai assertion library
import FetchAdapter from '@pollyjs/adapter-fetch'; // Fetch adapter for Polly
import FSPersister from '@pollyjs/persister-fs';
import NodeHttpAdapter from '@pollyjs/adapter-node-http';
import XHRAdapter from '@pollyjs/adapter-xhr';
// Register adapters and persisters with Polly.js
Polly.register(FetchAdapter); // Register the Fetch adapter
Polly.register(FSPersister);
Polly.register(NodeHttpAdapter);
Polly.register(XHRAdapter);
// Describe a test suite using a testing framework (e.g., Mocha or Jasmine)
describe('Simple Example', function () {
// Write a test case within the suite using the `it` function
it('fetches a post 1', async function () {
// Create a new Polly instance named 'Simple Example'
const polly = new Polly('Simple Example', {
adapters: ['node-http'],
persister: 'fs',
persisterOptions: {
fs: {
recordingsDir: 'recordings'
}
},
mode: 'replay', // Set the mode to 'replay' to use existing recordings
logLevel: 'info', // Log requests to the console with 'info' level
recordIfMissing: true
});
polly.server.get('https://jsonplaceholder.typicode.com/posts/8').intercept((req, res) => {
console.log('Request intercepted:', req);
console.log('Response intercepted:', res);
});
// // Stop the Polly instance, which persists recorded requests and disconnects from adapters
await polly.stop();
});
});`
I am using this code print request and responses for the above url. My code runs , and it says it is successful but it dosen't show any logs what I am trying to print. I am using mocha for running test. And chai is for assertion. I am not sure whether it is actually intercepting call or not. Can anyone help me with that. Thanks!
The text was updated successfully, but these errors were encountered:
Have a look at the documentation for test framework integration.
We had a bit of difficulty getting things working because the documentation & behaviour didn't match.
`import { Polly } from '@pollyjs/core';
import { expect } from 'chai'; // Chai assertion library
import FetchAdapter from '@pollyjs/adapter-fetch'; // Fetch adapter for Polly
import FSPersister from '@pollyjs/persister-fs';
import NodeHttpAdapter from '@pollyjs/adapter-node-http';
import XHRAdapter from '@pollyjs/adapter-xhr';
// Register adapters and persisters with Polly.js
Polly.register(FetchAdapter); // Register the Fetch adapter
Polly.register(FSPersister);
Polly.register(NodeHttpAdapter);
Polly.register(XHRAdapter);
// Describe a test suite using a testing framework (e.g., Mocha or Jasmine)
describe('Simple Example', function () {
// // Stop the Polly instance, which persists recorded requests and disconnects from adapters
await polly.stop();
});
});`
I am using this code print request and responses for the above url. My code runs , and it says it is successful but it dosen't show any logs what I am trying to print. I am using mocha for running test. And chai is for assertion. I am not sure whether it is actually intercepting call or not. Can anyone help me with that. Thanks!
The text was updated successfully, but these errors were encountered: