Skip to content

Instantly share code, notes, and snippets.

View kianaditya's full-sized avatar

Aditya Naik kianaditya

View GitHub Profile
@kianaditya
kianaditya / main.tour
Created March 28, 2023 07:47
Test scopes using jest tests
{
"$schema": "https://aka.ms/codetour-schema",
"title": "Testing scopes using jest",
"steps": [
{
"file": "src/components/MaterialStandard/materialStandard.scope.js",
"description": "We first build an array of objects, where each object contains information about setting up the test, and an assertion. \n\nAssertions included in this structure are - `inDocument`, `notInDocument`, and `calls` ( that tracks no of calls to an api)\n\nA standard structure for a \"test object\" is as follows:\n```js\n{\nname: \"<denotes name of the test that shows up when we run it>\"\ncomponent:<component under test>\nscope:<scope array takes in all the applicable scopes for testing>\nroute:<which route we should render the component with>\nassertion: <one of three assertions writtern as screen => screen ...>\nmockedRoute: <if we are asserting no of calls made to particular endpoint>\ncalls: <asserting no of calls>\n}\n```",
"line": 22,
"contents": "import React from 'react'\nimport * as materialS
{{% block normal %}}
This is a normal styled text block.
{{% /block %}}
{{% block info %}}
This is an info styled text block.
{{% /block %}}
{{% block warning %}}
This is an warning styled text block.
import {
Card,
Typography,
CardHeader,
Button,
Avatar,
} from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
const useStyles = makeStyles((theme) => ({
[
{
"userId": 1,
"id": 1,
"title": "Mocked Todo",
"completed": false
}
]
/// <reference types="Cypress" />
describe('Tests todo list', () => {
it('Checks todo render', () => {
cy.customRoute(
{
method: 'GET',
url: 'https://jsonplaceholder.typicode.com/todos',
response: 'fixture:todo.json',
},
Cypress.Commands.add('customRoute', (args, alias = 'mock') => {
cy.server()
if (Cypress.env('mock')) {
cy.route(args).as(alias)
}
})
/// <reference types="Cypress" />
describe('Tests todo list', () => {
it('Checks todo render', () => {
cy.visit('/')
cy.get('h3')
.should('have.length', 200)
.first()
.should('have.text', 'delectus aut autem')
})
@kianaditya
kianaditya / app.js
Created September 4, 2020 12:41
cypress toggle mocked routes
import React, { useState, useEffect } from 'react'
import Axios from 'axios'
const URL = 'https://jsonplaceholder.typicode.com/todos'
const App = () => {
const [todos, setTodos] = useState([])
useEffect(() => {
fetchTodos()
}, [])
import React, { useState, useEffect } from 'react'
import socketIOClient from 'socket.io-client'
const socket = socketIOClient('http://localhost:3000', {
transports: ['websocket'],
autoConnect: false,
})
const App = () => {
const [connectionStatus, setConnectionStatus] = useState(false)
@kianaditya
kianaditya / server.js
Last active July 20, 2020 07:48
socketIO api
const PORT = 3000
const app = require('express')()
const server = require('http').createServer(app)
const io = require('socket.io')(server, { serveClient: false })
const cors = require('cors')
app.use(cors())