Skip to content

Instantly share code, notes, and snippets.

testWidgets('should display a WordPair and update on button press', (WidgetTester tester) async {
await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => MyAppState(),
child: MaterialApp(home: MyHomePage()),
),
);
// Verify initial WordPair is displayed
expect(find.textContaining('_'), findsOneWidget);
@YonatanKra
YonatanKra / getBigCardText.dart
Created September 9, 2025 08:32
getBigCardText
String? getBigCardText(WidgetTester tester) {
final bigCard = find.byType(BigCard);
// Find the Text widget inside the BigCard
final textWidget = find.descendant(
of: bigCard,
matching: find.byType(Text),
);
// Get the actual text content from the rendered widget
@YonatanKra
YonatanKra / second_test.dart
Created September 9, 2025 08:31
Flutter widget second approach
testWidgets('should display “mock_first” in a big card', ( WidgetTester tester, ) async {
    await tester.pumpWidget(
      ChangeNotifierProvider<MyAppState>(
        create: (context) => MockAppState(),
        child: MaterialApp(home: MyHomePage()),
      ),
    );
    expect(getBigCardText(tester), equals('mock_first'));
  });
@YonatanKra
YonatanKra / first_test.dart
Created September 9, 2025 08:29
Flutter widget simple test - approach one
testWidgets(‘should display “mock_first” text’, (WidgetTester tester) async {
await tester.pumpWidget(
ChangeNotifierProvider<MyAppState>(
create: (context) => MockAppState(),
child: MaterialApp(home: MyHomePage()),
),
);
expect(find.text(‘mock_first’), findsOneWidget);
});
it('should send parsed output to the callback', async () => {
queueAgentFeedResponse(fullFeedResponseWithAlt);
queueAgentFeedResponse(fullFeedLastResponse);
const spy = vi.fn();
await bot.run(handle, 'password', spy);
describe('run()', () => {
it('should fire the callback on every streaming event', async () => {
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedLastResponse);
const spy = vi.fn();
await bot.run(handle, 'password', spy);
expect(spy).toHaveBeenCalledTimes(2);
async streamPosts(handle: string, onUpdate: (results: any) => any) {
while (true) {
try {
const result = await this.#agent.getAuthorFeed({
actor: handle,
it('should stream posts with done set to false when cursor is truthy', async () => {
const spy = vi.fn();
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedLastResponse);
describe('checkSinglePost()', () => {
it('should return the error message if fetch post failed', async () => {
resetAtpAgentMock();
const postUri = 'postUri';
const bot = new AltTextBot();
const error = { message: 'error' };
mockAtpAgent.getPost.mockRejectedValue(error);
const result = await bot.checkSinglePost(postUri);
import { AltTextBot } from './find-altless-posts.js';
let mockAtpAgent;
const resolvedHandle = {
did: 'handle-did'
};
const resetAtpAgentMock = () => {
mockAtpAgent = {