async function quickstart() {
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient();
// Performs label detection on the image file
const [result] = await client.labelDetection('./resources/wakeupcat.jpg');
const labels = result.labelAnnotations;
console.log('Labels:');
labels.forEach(label => console.log(label.description));
}
quickstart();
const {getQueriesFrom} = require('@testing-library/nightwatch')
module.exports = {
beforeEach(browser, done) {
browser.url('http://localhost:13370')
done()
},
async getByLabelText(browser) {
const {getByLabelText} = getQueriesFrom(browser)
const input = await getByLabelText('Label Text')
browser.setValue(input, '@TL FTW')
browser.expect.element(input).value.to.equal('@TL FTW')
},
async getByAltText(browser) {
const {getByAltText} = getQueriesFrom(browser)
const image = await getByAltText('Image Alt Text')
browser.click(image)
browser.expect
.element(image)
.to.have.css('border')
.which.equals('5px solid rgb(255, 0, 0)')
},
}
import '@testing-library/jest-dom'
import {render, fireEvent} from '@testing-library/svelte'
import Comp from '..'
test('count increments when button is clicked', async () => {
const {getByText} = render(Comp)
const button = getByText('Count is 0')
// Option 1.
await fireEvent.click(button)
expect(button).toHaveTextContent('Count is 1')
// Option 2.
await fireEvent(
button,
new MouseEvent('click', {
bubbles: true,
cancelable: true,
}),
)
expect(button).toHaveTextContent('Count is 2')
})
import React from 'react';
import { Button, View, Platform } from 'react-native';
import * as ScreenCapture from 'expo-screen-capture';
import * as MediaLibrary from 'expo-media-library';
export default class ScreenCaptureExample extends React.Component {
async componentDidMount() {
// This permission is only required on Android
const { status } = await MediaLibrary.requestPermissionsAsync();
if (status === 'granted') {
ScreenCapture.addScreenshotListener(() => {
alert('Thanks for screenshotting my beautiful app 😊');
});
}
}
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'space-around' }}>
<Button title="Activate" onPress={this._activate} />
<Button title="Deactivate" onPress={this._deactivate} />
</View>
);
}
_activate = async () => {
await ScreenCapture.preventScreenCaptureAsync();
};
_deactivate = async () => {
await ScreenCapture.allowScreenCaptureAsync();
};
}
// NOTE: jest-dom adds handy assertions to Jest and it is recommended, but not required.
import '@testing-library/jest-dom'
import {render, fireEvent} from '@testing-library/svelte'
import Comp from '../Comp'
test('shows proper heading when rendered', () => {
const {getByText} = render(Comp, {name: 'World'})
expect(getByText('Hello World!')).toBeInTheDocument()
})
// Note: This is as an async test as we are using `fireEvent`
test('changes button text on click', async () => {
const {getByText} = render(Comp, {name: 'World'})
const button = getByText('Button')
// Using await when firing events is unique to the svelte testing library because
// we have to wait for the next `tick` so that Svelte flushes all pending state changes.
await fireEvent.click(button)
expect(button).toHaveTextContent('Button Clicked')
})