This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const truncate = (phrase, maxLength) => { | |
if (phrase.length > maxLength) { | |
return `${phrase.substring(0, maxLength - 4)} ...` | |
} else { | |
return phrase | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const camelCaseToSnakeCase = (item) => { | |
return item.replace(/[\w]([A-Z])/g, (m) => { | |
return m[0] + '_' + m[1] | |
}).toLowerCase() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import isEqual from 'lodash/isEqual' | |
import isObject from 'lodash/isObject' | |
import transform from 'lodash/transform' | |
export const diffBetweenTwoObjects = (object, base) => { | |
const changes = (object, base) => { | |
return transform(object, (result, value, key) => { | |
if (!isEqual(value, base[key])) { | |
result[key] = (isObject(value) && isObject(base[key])) ? changes(value, base[key]) : value | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cypress.Commands.add('mockSockJs', () => { | |
const url = '/sockjs-node/info?t=*' | |
cy.server() | |
cy.route({ | |
method: 'GET', | |
url: url, | |
response: 'fixture:sockJs.json', | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Cypress Request to JSON Writer', () => { | |
const JSON_PLACEHOLDER_API_URL = 'https://jsonplaceholder.typicode.com' | |
const FILENAME = 'users.json' | |
it('Writes XHR to a JSON fixture file', () => { | |
const url = `${JSON_PLACEHOLDER_API_URL}/users` // the API call | |
// Use cy.request to hit the API url. Add bearer token if auth required for API. | |
cy.request({ | |
url: url, | |
auth: { |